Reputation: 458
I have a rails blog, with a PostgreSQL database, where I have a Post
model and PodcastNote
model. I want to add a 'Tag' model, where tags
can be for both posts
and podcast_notes
. In both cases, it will be a many-to-many relationship. My question is what is the best practice for handling that?
I can think of 2 ways:
Have 1 join model that connects tags
to both posts
and podcast_notes
.
Have 2 join models - one that connects tags
to posts
and another that connects tags
to podcast_notes
Which would be considered the best practice in this case?
If best practice is option 1 above, how would I go about doing that?
Upvotes: 0
Views: 47
Reputation: 5071
One join model with a polymorphic association is the way most tagging gems solve this.
https://github.com/mbleigh/acts-as-taggable-on
https://github.com/pat/gutentag
Upvotes: 3