2
我有这些模型:导轨 - 模型关联问题
class Profile
has_many :projects, :through => "teams"
has_many :teams, :foreign_key => "member_id"
has_many :own_projects, :class_name => "Project", :foreign_key => :profile_id
has_many :own_teams, :through => :own_projects, :source => :teams
end
class Project
belongs_to :profile, :class_name => "Profile"
has_many :teams
has_many :members, :class_name => "Profile", :through => "teams", :foreign_key => "member_id"
end
class Team
belongs_to :member, :class_name => 'Profile'
belongs_to :project
end
我想创建模型Evaluation
。它需要项目所有者的ID,项目成员的ID以及项目的ID。更好地解释,项目的业主将逐一评估他的所有成员。成员将评估只是该项目的所有者。表评估将具有很多属性加上以前提到的那些Id。
我的问题是:我的模型将如何使其与评估功能,以及如何将模型评估本身? has_and_belongs_to_many
或has_many :through
?
谢谢。
编辑
瞎猜
class Evaluations < ActiveRecord::Base
belongs_to :evaluated, :class_name => 'Profile', :foreign_key => "evaluated_id"
belongs_to: :evaluator, :class_name => 'Profile', :foreign_key => "profile_id"
end
猜猜我将不再需要从项目的ID ...
'has_and_belongs_to_many'不允许您在表格中拥有额外的属性,所以从一开始就是不行的。 – bruno077 2011-05-23 20:57:34
这也是我的初衷。感谢你的回答! – Luk 2011-05-23 21:05:42
您在#6133064 – Yardboy 2011-05-26 19:15:23