Module: LinkedRails::Model::Dirty

Extended by:
ActiveSupport::Concern
Included in:
LinkedRails::Model
Defined in:
lib/linked_rails/model/dirty.rb

Instance Method Summary collapse

Instance Method Details

#previously_changed_relations(inverted = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/linked_rails/model/dirty.rb', line 25

def previously_changed_relations(inverted = nil)
  serializer_class = RDF::Serializers.serializer_for(self)
  return {} unless serializer_class.try(:relationships_to_serialize)

  serializer_class.relationships_to_serialize.select do |key, _value|
    if respond_to?(key)
      association_key = key.to_s.ends_with?('_collection') ? send(key).association : key
      association_has_destructed?(association_key) || association_changed?(association_key, inverted)
    end
  end.with_indifferent_access
end