← Back to Upcase

HABTM -- twice with the same two models

(Brian Dear) #1


has_and_belongs_to_many :editors, class_name: 'User', association_foreign_key: 'editor_id' has_and_belongs_to_many :users

What’s happening here is that users can be editors of one or many projects
They can also just be a “member” of one or many projects (not necessarily the same projects for which they might be an editor)

So in the User model I am at a confusion point:

I need
has_and_belongs_to_many :projects however I need something for the “editor” relationship as well.

So two joins: a users_projects join and an editors_projects.

I just can figure out how to do the associations to make that happen.

Thanks for the help!