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