我试图模拟一个出版物。的出版物有多个作者和编辑。因为它是可能的,一个人是一个出版物的作者和其他的编辑,作者和编辑没有独立的模型:的habtm多次用相同型号
class Publication < ActiveRecord::Base
has_and_belongs_to_many :authors, :class_name=>'Person'
has_and_belongs_to_many :editors, :class_name=>'Person'
end
上面的代码不起作用,因为它使用相同的连接表。现在我,现在我可以指定连接表的名称,但API文档中的警告是关于这一警告,我不明白:
:join_table: 指定的名称连接表如果基于词法顺序 默认是不是你想要的。警告:如果 您正在覆盖任一类的表名称 ,则必须声明table_name方法 必须在 has_and_belongs_to_many声明的下面 为了工作。
http://blog.hasmanythrough.com/2006/4/20/many-to-many-dance-off – 2010-05-11 19:08:03