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:
parent
00cd3789f6
commit
f17bb1fbff
1 changed files with 5 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue