我有以下型号:型号遍历轨道:从小孩到兄弟姐妹的孩子
class Advisor < ActiveRecord::Base
belongs_to :course
end
class Course < ActiveRecord::Base
has_many :advisors
has_many :sessions
has_many :materials, :through=>:sessions
end
class Session < ActiveRecord::Base
belongs_to :course
has_many :materials
end
class Material < ActiveRecord::Base
belongs_to :session
end
即每个顾问讲授一门课程,每门课程都有会话,每个会话都有材料。 我想从一个顾问的所有相关材料,即横贯东西,如:Advisor.first.materials
我试图做的:
class Advisor < ActiveRecord::Base
belongs_to :course
has_many :sessions, :through=>:course
has_many :materials, :through=>:sessions
end
但是,因为它处理会话作为一个多到多台没有奏效:Unknown column 'sessions.advisor_id' in 'where clause': SELECT 'material'.* FROM 'materials' INNER JOIN 'sessions' ON 'materials'.session_id = 'sessions'.id WHERE (('sessions'.advisor_id = 1))
然后我试图做的:
class Advisor < ActiveRecord::Base
belongs_to :course
has_many :materials, :through=>:course
end
在试图拥有该协会使用“材料”协会在“场”的模式,但收到:
ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection on macro :has_many :through for has_many :materials, :through=>:sessions. Use :source to specify the source reflection.
试图使用“会议”作为源,这是一个不错的尝试,但让我只接收会议,而不是材料。
任何想法,如果这是可能的? 我正在使用Rails 2.3.8(也许是时间升级?)
谢谢! 阿米特
你是对的,我很愚蠢的错过了......谢谢! – AmitA 2010-10-31 16:31:34