From 7c5c1a07c03ec03536636c26e09b80b29a59beed Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 14 Nov 2010 21:54:24 -0500 Subject: if association is already loaded and if a find operation is performed on the already loaded association list with an empty hash then do not perform another sql [#5972 state:resolved] --- activerecord/lib/active_record/associations/association_collection.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 71d8c2d3c8..5b34ac907c 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -75,6 +75,7 @@ module ActiveRecord find(:first, *args) else load_target unless loaded? + args = args[1..-1] if args.first.kind_of?(Hash) && args.first.empty? @target.first(*args) end end @@ -544,7 +545,7 @@ module ActiveRecord end def fetch_first_or_last_using_find?(args) - args.first.kind_of?(Hash) || !(loaded? || !@owner.persisted? || @reflection.options[:finder_sql] || + (args.first.kind_of?(Hash) && !args.first.empty?) || !(loaded? || !@owner.persisted? || @reflection.options[:finder_sql] || !@target.all? { |record| record.persisted? } || args.first.kind_of?(Integer)) end -- cgit v1.2.3