1
0
Fork 0
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:
Pratik Naik 2009-12-27 22:32:20 +05:30
parent bbdeaae2ca
commit 5565bab994

View file

@ -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