diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-30 01:16:24 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-30 01:16:24 +0530 |
commit | f17bb1fbff122e94efb3e29f9ce40001c7ee1145 (patch) | |
tree | f53455626f955fc76f3ad691e590d09fbf64b6d0 /activerecord | |
parent | 00cd3789f6d53163229669ad82a5d87fcdcb49ba (diff) | |
download | rails-f17bb1fbff122e94efb3e29f9ce40001c7ee1145.tar.gz rails-f17bb1fbff122e94efb3e29f9ce40001c7ee1145.tar.bz2 rails-f17bb1fbff122e94efb3e29f9ce40001c7ee1145.zip |
Simplify get_projection_name_from_chained_relations using recursion
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relational_calculations.rb | 17 |
1 files 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 |