1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Simplify get_projection_name_from_chained_relations using recursion

This commit is contained in:
Pratik Naik 2009-12-30 01:16:24 +05:30
parent 00cd3789f6
commit f17bb1fbff

View file

@ -165,19 +165,12 @@ module ActiveRecord
column ? column.type_cast(value) : value
end
def get_projection_name_from_chained_relations
name = nil
if @relation.respond_to?(:projections) && @relation.projections.present?
name = @relation.send(:select_clauses).join(', ')
elsif @relation.respond_to?(:relation) && relation = @relation.relation
while relation.respond_to?(:relation)
if relation.respond_to?(:projections) && relation.projections.present?
name = relation.send(:select_clauses).join(', ')
end
relation = relation.relation
end
def get_projection_name_from_chained_relations(relation = @relation)
if relation.respond_to?(:projections) && relation.projections.present?
relation.send(:select_clauses).join(', ')
elsif relation.respond_to?(:relation)
get_projection_name_from_chained_relations(relation.relation)
end
name
end
end