【发布时间】:2010-05-20 17:33:28
【问题描述】:
我有以下设置:
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 的错误。我该如何解决?
我是否应该为作者和编辑切换到单独的模型?然而,它会给数据库带来一些冗余,因为一个人可以是一个出版物的作者和另一个出版物的编辑。
【问题讨论】:
标签: ruby-on-rails has-and-belongs-to-many