Class: Locomotive::Steam::Models::ManyToManyAssociation

Inherits:
ReferencedAssociation show all
Defined in:
lib/locomotive/steam/models/associations/many_to_many.rb

Instance Attribute Summary

Attributes inherited from ReferencedAssociation

#repository

Instance Method Summary collapse

Methods inherited from ReferencedAssociation

#__attach__, #__call_block_once__, #__name__, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Locomotive::Steam::Models::ReferencedAssociation

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Locomotive::Steam::Models::ReferencedAssociation

Instance Method Details

#__load__Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/locomotive/steam/models/associations/many_to_many.rb', line 6

def __load__
  key = @repository.k(:_id, :in)

  @repository.local_conditions[key] = @entity[__target_key__] || []

  # use order_by from options as the default one for further queries
  @repository.local_conditions[:order_by] = @options[:order_by] unless @options[:order_by].blank?

  # all the further calls (method_missing) will be delegated to @repository
  @repository
end

#__serialize__(attributes) ⇒ Object



18
19
20
21
22
# File 'lib/locomotive/steam/models/associations/many_to_many.rb', line 18

def __serialize__(attributes)
  attributes[__target_key__] = attributes[__name__].try(:map, &:_id)

  attributes.delete(__name__)
end

#__target_key__Object



24
25
26
# File 'lib/locomotive/steam/models/associations/many_to_many.rb', line 24

def __target_key__
  :"#{__name__.to_s.singularize}_ids"
end