Module: Torque::PostgreSQL::Associations::Preloader::LoaderQuery

Defined in:
lib/torque/postgresql/associations/preloader/loader_query.rb

Instance Method Summary collapse

Instance Method Details

#connected_through_array?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/torque/postgresql/associations/preloader/loader_query.rb', line 26

def connected_through_array?
  !association_key_name.is_a?(Array) && foreign_column&.array?
end

#foreign_columnObject



8
9
10
# File 'lib/torque/postgresql/associations/preloader/loader_query.rb', line 8

def foreign_column
  @foreign_column ||= scope.columns_hash[association_key_name.to_s]
end

#load_records_for_keys(keys, &block) ⇒ Object



12
13
14
15
16
17
# File 'lib/torque/postgresql/associations/preloader/loader_query.rb', line 12

def load_records_for_keys(keys, &block)
  condition = query_condition_for(keys)
  return super if condition.nil?

  scope.where(condition).load(&block)
end

#query_condition_for(keys) ⇒ Object



19
20
21
22
23
24
# File 'lib/torque/postgresql/associations/preloader/loader_query.rb', line 19

def query_condition_for(keys)
  return unless connected_through_array?

  value = scope.cast_for_condition(foreign_column, keys.to_a)
  scope.table[association_key_name].overlaps(value)
end