Skip to content

Commit 34266dc

Browse files
author
Arthur Chui
committed
Use a different variable name to avoid overriding the custom table_alias_name
1 parent b51e414 commit 34266dc

File tree

1 file changed

+5
-4
lines changed
  • lib/jit_preloader/active_record

1 file changed

+5
-4
lines changed

lib/jit_preloader/active_record/base.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,24 @@ def has_many_aggregate(assoc, name, aggregate, field, table_alias_name: nil, def
7777
association_scope = association_scope.instance_exec(&reflection.scope).reorder(nil) if reflection.scope
7878

7979
# If the query uses an alias for the association, use that instead of the table name
80-
table_alias_name ||= association_scope.references_values.first || aggregate_association.table_name
80+
table_reference = table_alias_name
81+
table_reference ||= association_scope.references_values.first || aggregate_association.table_name
8182

82-
conditions[table_alias_name] = { aggregate_association.foreign_key => primary_ids }
83+
conditions[table_reference] = { aggregate_association.foreign_key => primary_ids }
8384

8485
# If the association is a STI child model, specify its type in the condition so that it
8586
# doesn't include results from other child models
8687
parent_is_base_class = aggregate_association.klass.superclass.abstract_class? || aggregate_association.klass.superclass == ActiveRecord::Base
8788
has_type_column = aggregate_association.klass.column_names.include?(aggregate_association.klass.inheritance_column)
8889
is_child_sti_model = !parent_is_base_class && has_type_column
8990
if is_child_sti_model
90-
conditions[table_alias_name].merge!({ aggregate_association.klass.inheritance_column => aggregate_association.klass.sti_name })
91+
conditions[table_reference].merge!({ aggregate_association.klass.inheritance_column => aggregate_association.klass.sti_name })
9192
end
9293

9394
if reflection.type.present?
9495
conditions[reflection.type] = self.class.name
9596
end
96-
group_by = "#{table_alias_name}.#{aggregate_association.foreign_key}"
97+
group_by = "#{table_reference}.#{aggregate_association.foreign_key}"
9798

9899
preloaded_data = Hash[association_scope
99100
.where(conditions)

0 commit comments

Comments
 (0)