我有一个服务类型表,其中包含几十个服务的ID和名称.
我有一个Projects表,必须有一个Proposed Services列表和一个Accepted Services列表.
我知道我会在两侧使用HABTM,其间有一个project_service_types表.
当我在同一个表之间有两个不同的关系时,我无法弄明白该怎么做.我怀疑它使用:join_table和:associated_forign_key,但我不能让它在我的应用程序中工作.
谢谢.
我用HABTM解决了它...
class ServiceType < ActiveRecord::Base has_and_belongs_to_many :accepted_projects, :class_name => "Project", :join_table => :projects_accepted_types has_and_belongs_to_many :proposed_projects, :class_name => "Project", :join_table => :projects_proposed_types end class Project < ActiveRecord::Base has_and_belongs_to_many :accepted_types, :class_name => "ServiceType", :join_table => :projects_accepted_types has_and_belongs_to_many :proposed_types, :class_name => "ServiceType", :join_table => :projects_proposed_types end