habtm multiple times with the same model

Posted by Ermin on Stack Overflow See other posts from Stack Overflow or by Ermin
Published on 2010-05-10T16:32:56Z Indexed on 2010/05/10 16:44 UTC
Read the original article Hit count: 229

Filed under:
|

I am trying to model a publications. A publication can have multiple authors and editors. Since it is possible that one person is an author of one publication and an editor of another, no separate models for Authors and Editors:

class Publication < ActiveRecord::Base
  has_and_belongs_to_many :authors, :class_name=>'Person'
  has_and_belongs_to_many :editors, :class_name=>'Person'
end

The above code doesn't work, because it uses the same join table. Now I now that I can specify the name of the join table, but there is a warning in the API documentation is a warning about that which I don't understand:

:join_table: Specify the name of the join table if the default based on lexical order isn’t what you want. WARNING: If you’re overwriting the table name of either class, the table_name method MUST be declared underneath any has_and_belongs_to_many declaration in order to work.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about habtm