I'm using the paper_trail-association_tracking gem to save PaperTrail versions for AR associations. I have a model, let's call it User, that has many Groups and has many Skills. Both of these associations have join tables (user_groups
and user_skills
). So my User model has two has_many :through
associations. All of the models (User, Group, Skill, UserSkill, UserGroup) have PaperTrail enabled on them.
class User < ApplicationRecord
has_paper_trail
has_many :groups, through: user_groups
has_many :user_groups
has_many :skills, through: user_skills
has_many :user_skills
end
Say I want to reify
an earlier version of the User model, along with their Skills (user_skills
records), but not revert to an earlier version of the user's Groups (user_groups
). The code looks something like this:
me = User.find(1)
older_me = me.versions.last.reify(has_many: true)
older_me.save
This will reify both UserGroups and UserSkills for this User, but I want it to reify just UserSkills. It seems the gem will reify all associations automatically, based on this source code I looked through.
So is there a way to specify which association I want to be reified? Or is it not best practices to do this? For my use case, I can't see a problem with this unless the user itself was actually deleted or something like that.
Sorry my models here sound kinda weird, I tried to use something generic and simplified, my real use case and models are a bit complex but this question demonstrates the bottom line of my issue.
x
to remember the user's groups and when thereify
is done, setuser.user_groups = x
? – Inclusive