23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/active_record_aliased_joins.rb', line 23
def joins_with_alias(association_name, alias_name, join_klass = Arel::Nodes::InnerJoin)
reflection = _reflect_on_association(association_name.to_s)
raise ActiveRecord::AssociationNotFoundError unless reflection
source_joins =
case reflection
when ActiveRecord::Reflection::HasManyReflection, ActiveRecord::Reflection::HasOneReflection
join_with_alias_has_many_has_one(reflection, association_name, alias_name, join_klass)
when ActiveRecord::Reflection::BelongsToReflection
join_with_alias_belongs_to(reflection, association_name, alias_name, join_klass)
when ActiveRecord::Reflection::ThroughReflection, ActiveRecord::Reflection::HasAndBelongsToManyReflection
join_with_alias_through(reflection, association_name, alias_name, join_klass)
else
raise UnsupportedReflectionError, reflection
end
joins(source_joins.join_sources)
end
|