Class: EagerGroup::Preloader::HasManyThroughBelongsTo
Instance Attribute Summary
#arguments, #definition, #klass, #record_ids, #reflection
Instance Method Summary
collapse
#definition_scope, #initialize
Instance Method Details
#aggregate_hash ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/eager_group/preloader/has_many_through_belongs_to.rb', line 10
def aggregate_hash
scope = reflection.klass.all.tap{|query| query.merge!(definition_scope) if definition_scope }
scope.where(group_by_foreign_key => record_ids).
where(polymophic_as_condition).
group(group_by_foreign_key).
send(definition.aggregation_function, definition.column_name)
end
|
#group_by_foreign_key ⇒ Object
6
7
8
|
# File 'lib/eager_group/preloader/has_many_through_belongs_to.rb', line 6
def group_by_foreign_key
"#{reflection.table_name}.#{reflection.through_reflection.klass.reflect_on_association(reflection.name).foreign_key}"
end
|
#group_by_key ⇒ Object
19
20
21
|
# File 'lib/eager_group/preloader/has_many_through_belongs_to.rb', line 19
def group_by_key
reflection.through_reflection.foreign_key
end
|
#polymophic_as_condition ⇒ Object
23
24
25
|
# File 'lib/eager_group/preloader/has_many_through_belongs_to.rb', line 23
def polymophic_as_condition
reflection.type ? { reflection.name => { reflection.type => reflection.through_reflection.klass.base_class.name } } : []
end
|