While doing some refactoring I ran into a situation where I would like to change the format of the tag names. Initially I tried to just simply migrate by altering the name of the affected ActsAsTaggableOn::Tag records but the issue is that some of the new tag names already exist for different tag contexts.
I could find_each the tagged objects and update them one by one but this is slow and I don't want to touch (updated_at) the records since they didn't really change. Then I thought of renaming the tag unless it exists in which case I would just update the tag_id on the Tagging but then I'm afraid it will mess with the taggings_count or something else.
Is there a way to easily change tags on a record without having to save the record itself? The documentation only really features model extensions and finder methods.
Disclaimer: we got rid of
acts_as_taggable_onyears ago, so I haven't had a chance to use it in a while and have not tested the below solution.With that said, what you mentioned seems like the way to go.
ActiveRecord::Relation.update_allgoes straight to SQL and does not touch the related records.ActiveRecord::CounterCache.update_countersalso does not touch records by default.