module DirtyAssociations
This concern can be used to monitor associations for changes.
Associations monitored using the methods in this concern will show up in the ActiveRecord model's changes, changed and previous_changes methods.
Constants
- VERSION
Private Instance Methods
_association_will_change?(association, value)
click to toggle source
# File lib/dirty_associations.rb, line 51 def _association_will_change?(association, value) send(association) != value end
_ids_will_change?(ids, value)
click to toggle source
# File lib/dirty_associations.rb, line 55 def _ids_will_change?(ids, value) value = Array(value).reject &:blank? send(ids).map(&:to_s) != value.map(&:to_s) end
_nested_attributes_will_change?(attributes_collection)
click to toggle source
# File lib/dirty_associations.rb, line 60 def _nested_attributes_will_change?(attributes_collection) return false unless attributes_collection.is_a?(Array) || attributes_collection.is_a?(Hash) attributes_collection = attributes_collection.values if attributes_collection.is_a? Hash # Only consider additions to be a change, i.e. attributes hashes with no id. Editing or destroying a # nested model can be detected by belongs_to :touch => true on the nested model class. attributes_collection.any? { |a| a[:id].blank? && a["id"].blank?} end