Module: Synchronisable::DSL::Associations::ClassMethods

Defined in:
lib/synchronisable/dsl/associations.rb

Instance Method Summary collapse

Instance Method Details

#associations_for(attrs) ⇒ Hash<Synchronisable::Association, Array>

Builds hash with association as key and array of ids as value.

Raises:

  • (MissedAssocationsError)

    raised when the given attributes hash doesn’t required associations



30
31
32
33
34
35
36
37
# File 'lib/synchronisable/dsl/associations.rb', line 30

def associations_for(attrs)
  ensure_required_associations(attrs)
  intersection = self.associations.map { |key, _| key } & attrs.keys

  Hash[intersection.map { |key|
    [self.associations[key], [*attrs[key].dup]]
  }]
end