From f17bb1fbff122e94efb3e29f9ce40001c7ee1145 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 30 Dec 2009 01:16:24 +0530 Subject: [PATCH] Simplify get_projection_name_from_chained_relations using recursion --- .../active_record/relational_calculations.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/activerecord/lib/active_record/relational_calculations.rb b/activerecord/lib/active_record/relational_calculations.rb index 5e5ea9e0c1..f42ffe0460 100644 --- a/activerecord/lib/active_record/relational_calculations.rb +++ b/activerecord/lib/active_record/relational_calculations.rb @@ -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