Class: Datamappify::Data::Criteria::ActiveRecord::FindMultiple

Inherits:
Relational::FindMultiple show all
Defined in:
lib/datamappify/data/criteria/active_record/find_multiple.rb

Instance Attribute Summary

Attributes inherited from Relational::FindMultiple

#primaries, #secondaries

Attributes inherited from Common

#attributes, #attributes_and_values, #criteria, #entity, #options, #source_class

Instance Method Summary collapse

Methods inherited from Relational::FindMultiple

#data_record_for, #initialize, #perform, #record_value_for, #update_entity, #updated_attributes

Methods inherited from Common

#any_attribute, #default_source_class_name, #ignore?, #ignore_attribute?, #initialize, #key_name, #key_value, #new_record?, #perform_with_callbacks, #pk, #primary_record?, #store_attribute_value

Constructor Details

This class inherits a constructor from Datamappify::Data::Criteria::Relational::FindMultiple

Instance Method Details

#recordsArray (private)

Returns:

  • (Array)


11
12
13
14
15
# File 'lib/datamappify/data/criteria/active_record/find_multiple.rb', line 11

def records
  source_class.joins(@secondaries.map(&:source_key)).where(
    structured_criteria(primaries, secondaries)
  )
end

#structured_criteria(primaries, secondaries) ⇒ Hash (private)

Parameters:

  • primaries (Array<Attribute>)
  • secondaries (Array<Attribute>)

Returns:

  • (Hash)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datamappify/data/criteria/active_record/find_multiple.rb', line 22

def structured_criteria(primaries, secondaries)
  _criteria = {}

  primaries.each do |primary|
    _criteria[primary.source_attribute_key] = primary.value
  end

  secondaries.each do |secondary|
    _criteria[secondary.source_table] ||= {}
    _criteria[secondary.source_table][secondary.source_attribute_key] = secondary.value
  end

  _criteria
end