I have a situation where Project can have many Tags (and vice versa), so I have set up a has_and_belongs_to_many relationship between the two.
My question is this: I need a project to have the ability to carry a single current tag.
Option 1
Can I add a tag_id to my Project table? How do I set up the relationship correctly, given there is already a `projects_tags’ model?
Option 2
I’d imagine it isn’t effective to have the projects_tags model carry a boolean current field, because it would require additional queries in practice for me to find the right relationship. I just throw it out there as an alternative I’ve considered.
You could use something like this:
And then have
current_tag_idin yourprojectstable.You can’t add
currenttoprojects_tagsbecause it’s not technically a model: it’s only a join table. You’d have to incorporate another model and usehas_many :throughto do it that way.