aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb32
1 files changed, 13 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index b85d76e8d3..ac970f02b1 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -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
+ merge_options_from_reflection!(options)
+ construct_find_options!(options)
+
+ find_scope = construct_scope[:find].slice(:conditions, :order)
+
+ with_scope(:find => find_scope) do
+ relation = @reflection.klass.send(:construct_finder_arel_with_includes, options)
- if options[:order] && @reflection.options[:order]
- options[:order] = "#{options[:order]}, #{@reflection.options[:order]}"
- elsif @reflection.options[:order]
- options[:order] = @reflection.options[:order]
+ case args.first
+ when :first, :last, :all
+ relation.send(args.first)
+ else
+ relation.find(*args)
+ end
end
-
- # Build options specific to association
- construct_find_options!(options)
-
- merge_options_from_reflection!(options)
-
- # Pass through args exactly as we received them.
- args << options
- @reflection.klass.find(*args)
end
end