mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Rewrite AssociationCollection#find using relations
This commit is contained in:
parent
bbdeaae2ca
commit
5565bab994
1 changed files with 14 additions and 20 deletions
|
@ -52,27 +52,21 @@ module ActiveRecord
|
|||
load_target.select { |r| ids.include?(r.id) }
|
||||
end
|
||||
else
|
||||
conditions = "#{@finder_sql}"
|
||||
if sanitized_conditions = sanitize_sql(options[:conditions])
|
||||
conditions << " AND (#{sanitized_conditions})"
|
||||
end
|
||||
|
||||
options[:conditions] = conditions
|
||||
|
||||
if options[:order] && @reflection.options[:order]
|
||||
options[:order] = "#{options[:order]}, #{@reflection.options[:order]}"
|
||||
elsif @reflection.options[:order]
|
||||
options[:order] = @reflection.options[:order]
|
||||
end
|
||||
|
||||
# Build options specific to association
|
||||
merge_options_from_reflection!(options)
|
||||
construct_find_options!(options)
|
||||
|
||||
merge_options_from_reflection!(options)
|
||||
find_scope = construct_scope[:find].slice(:conditions, :order)
|
||||
|
||||
# Pass through args exactly as we received them.
|
||||
args << options
|
||||
@reflection.klass.find(*args)
|
||||
with_scope(:find => find_scope) do
|
||||
relation = @reflection.klass.send(:construct_finder_arel_with_includes, options)
|
||||
|
||||
case args.first
|
||||
when :first, :last, :all
|
||||
relation.send(args.first)
|
||||
else
|
||||
relation.find(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue