You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Association between models not created when setting IDs and calling save. Dirty tracking will always return [nil, nil] even when setting IDs to the same IDs.
Gem: 0.2.1
Rails: 5.1
The text was updated successfully, but these errors were encountered:
The Dirty implementation in Rails 5.2 has changed to operate only against AR attributes. Changes are still propagated but dirty tracking is lost w 5.2. I will need to do a rethink/rewrite. Thx.
I added an extra column user_ids_cache to the projects table that gets updated by the after_ callbacks of the association. By aliasing some attributes you should get the same result as before.
class AddUserIdsCacheToPatch < ActiveRecord::Migration[5.2]
def change
add_column :projects, :user_ids_cache, :text
end
end
class Project
serialize :user_ids_cache, Array
has_many :users, after_add: cache_user_ids,
after_remove: cache_user_ids
alias_attribute :user_ids_changed, :user_ids_cache_changed
alias_attribute :user_ids_was, :user_ids_cache_was
private
def cache_user_ids
self.user_ids_cache = user_ids.sort
end
...
end
Association between models not created when setting IDs and calling save. Dirty tracking will always return
[nil, nil]
even when setting IDs to the same IDs.Gem: 0.2.1
Rails: 5.1
The text was updated successfully, but these errors were encountered: