101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/activerecord/track_dirty_associations.rb', line 101
def association_changes association_type
association_changes = dirty_assocs&.dig(association_type) || {}
changes = []
assocs = send association_type
assocs = [assocs] unless assocs.is_a? Enumerable
assocs.each do |assoc|
assoc_changes = {}
assoc_changes.merge!(assoc.changes) if assoc.respond_to?(:changes)
assoc_changes.merge!(assoc.dirty_associations) if assoc.respond_to?(:dirty_associations)
changes << assoc_changes if assoc_changes.any?
end
association_changes[:changes] = changes if changes.any?
association_changes
end
|