Two Different Types of Associatons on the Same Two Tables in Rails

Posted by tmo256 on Stack Overflow See other posts from Stack Overflow or by tmo256
Published on 2010-06-11T20:04:23Z Indexed on 2010/06/11 22:43 UTC
Read the original article Hit count: 208

I have two models, users and themes, that I'm currently joining in a HABTM association in a themes_users table. Basically, after a user creates a new theme, it becomes available to other users to select for their own use.

However, only the original creator of the theme should have the ability to edit it. So, I need to have some other kind of association to handle that relationship, something like an created_by_id field in the theme.

In this way, the user model acts as two different roles: they can be an implementer of a theme AND/OR the owner of the theme. The implementer relationship is handled by the themes_users join table; the question is: What is the right way to handle this secondary association? Do I need to make users polymorphic and then make the created_by_id reference an "owner"? Or is there something easier?

Thanks so much for your help!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about polymorphic-associations