I have a web app where I have posts, and each post has and belongs to many tags. I want the tags associated with each post to be editable using a single text field, as a comma separated list. This allows tags to be added, removed and edited(a removal and an addition). However, my web app has no idea what is removed and deleted, as it is just passed an array of tags that I want the post to have.
I can think of 2 ways of handling this:
- Remove all the associations between tags and the post, and rebuild them.
- Fetch an array of tags before editing, do a comparison to find out which ones to add an remove.
What is the best way of handling this situation, and why?
What I ended up doing was just deleting all the tags associated with that post, and rebuilding them.