lib/counter_culture/extensions.rb in counter_culture-1.4.0 vs lib/counter_culture/extensions.rb in counter_culture-1.5.0
- old
+ new
@@ -109,17 +109,12 @@
# figure out whether the applicable counter cache changed (this can happen
# with dynamic column names)
counter_cache_name_was = counter.counter_cache_name_for(counter.previous_model(self))
counter_cache_name = counter.counter_cache_name_for(self)
- if Rails.version >= "5.1.0"
- foreign_key_changed = saved_changes[counter.first_level_relation_foreign_key].present?
- delta_column_changed = (counter.delta_column && saved_changes[counter.delta_column].present?)
- else
- foreign_key_changed = attribute_changed?(counter.first_level_relation_foreign_key)
- delta_column_changed = (counter.delta_column && attribute_changed?(counter.delta_column))
- end
- if foreign_key_changed || delta_column_changed || counter_cache_name != counter_cache_name_was
+ if counter.first_level_relation_changed?(self) ||
+ (counter.delta_column && counter.attribute_changed?(self, counter.delta_column)) ||
+ counter_cache_name != counter_cache_name_was
# increment the counter cache of the new value
counter.change_counter_cache(self, :increment => true, :counter_column => counter_cache_name)
# decrement the counter cache of the old value
counter.change_counter_cache(self, :increment => false, :was => true, :counter_column => counter_cache_name_was)