Hey guys,
What do you think about tracking habtm changes?
Apparently we can’t do that because when you change a habtm association it is changed immediately on database instead of waiting the save call (not sure why and the problem may not be because of that).
Current behaviour:
profile.roles_ids
=>
profile.update_attributes(:name => nil, :roles_ids => […])
=> false
profile.changes
{ “name” => [‘Admin’, nil] }
Expected behaviour:
profile.roles_ids
=>
profile.update_attributes(:name => nil, :roles_ids => […])
=> false
profile.changes
{ “name” => [‘Admin’, nil], :roles_ids => [, […]] }
Giving some problem context, I have an application that need to audit almost every change and I can track everything using the changes method but habtm changes.
We can write a solution like storing the initial state of roles_ids in an after_initialize callback on the model and comparing it on a after_save but I was thinking in a more “native” solution.
What do you think?