class Profile
has_many :projects, :through => "teamss"
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
。我想要做的是在project#view
页面为每个项目成员(包括所有者)生成一个链接,以便制作一个Evaluation
此人将点击链接并评估与此链接相关的人员。 Project
的所有者将评估所有成员,所有成员将评估所有者。帮助在Rails中建立模型
我已经定义模式Evaluation
如下,但我想我错过了什么:
class Evaluations < ActiveRecord::Base
belongs_to :evaluated, :class_name => 'Profile', :foreign_key => "evaluated_id"
belongs_to: :profile, :class_name => 'Profile', :foreign_key => "profile_id"
end
记住,Evaluation
表将有万吨的属性,这就是为什么我会不has_many_and_belongs_to_many
去。
如何创建此模型以便做我想做的事,并且能够通过project#show
页面获取我需要的所有内容?
谢谢!
编辑
变化做:
class Profile
has_many :evaluations, :dependent => :destroy, :foreign_key => :evaluation_id
has_many :evaluators, :through => :evaluations, :foreign_key => :profile_id
end
class Project
has_many :evaluations,:foreign_key => "project_id"
end
class Evaluations < ActiveRecord::Base
belongs_to :evaluated, :class_name => 'Profile', :foreign_key => "evaluated_id"
belongs_to: :profile, :class_name => 'Profile', :foreign_key => "profile_id"
belongs_to: :project, :class_name => 'Project', :foreign_key => "project_id"
end
是为配置文件所附的每个项目创建的新评估吗?如果是这样,似乎评估应该'belongs_to:project' – 2011-05-23 23:36:47
项目整体就像一个连接器。例如:我评估了Project X的所有者,因为我是Project X的成员。但由于评估链接将在'project#show'中,所以我想你可能是对的。 – Luk 2011-05-23 23:39:16