我有以下设置:如何在相同的两个类之间执行多个has_and_belongs_to_many关联?
class Publication < ActiveRecord::Base
has_and_belongs_to_many :authors, :class_name=>'Person', :join_table => 'authors_publications'
has_and_belongs_to_many :editors, :class_name=>'Person', :join_table => 'editors_publications'
end
class Person < ActiveRecord::Base
has_and_belongs_to_many :publications
end
有了这个设置,我可以做的东西一样Publication.first.authors
。但是,如果我想列出涉及某人的所有出版物Person.first.publications
,则会抛出关于丢失的连接表people_publications
的错误。我怎么能解决这个问题?
我是否应该改用作者和编辑的独立模型?然而,它会给数据库带来一些冗余,因为一个人可以是一个出版物的作者和另一个出版物的编辑。
has_and_belongs_to_many另一个关联:authored_publications,:CLASS_NAME => “出版”,:join_table =>:authors_publications – 2010-05-21 13:05:05
has_and_belongs_to_many:edited_publications,:CLASS_NAME => “出版” ,:join_table =>:editors_publications – 2010-05-21 13:06:19