Class: Datamappify::Data::Criteria::Sequel::FindMultiple

Inherits:
Relational::FindMultiple show all
Defined in:
lib/datamappify/data/criteria/sequel/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
16
17
18
19
# File 'lib/datamappify/data/criteria/sequel/find_multiple.rb', line 11

def records
  query_builder = source_class

  secondaries.each do |secondary|
    query_builder = query_builder.join(secondary.source_table, secondary.primary_reference_key => :id)
  end

  query_builder.where(structured_criteria(primaries, secondaries))
end

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

Parameters:

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

Returns:

  • (Hash)


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datamappify/data/criteria/sequel/find_multiple.rb', line 26

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}__#{secondary.source_attribute_name}"] = secondary.value
  end

  _criteria
end