From 4307d7ecbe897880a59ae2da717a893ccf0f3fde Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 13 Sep 2005 10:15:54 +0000 Subject: Fixed various problems with has_and_belongs_to_many when using customer finder_sql #2094 [Florian Weber] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2233 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../associations/has_and_belongs_to_many_association.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index d08e47378f..d386a5a906 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -52,9 +52,9 @@ module ActiveRecord ids = args.flatten.compact.uniq if ids.size == 1 - id = ids.first + id = ids.first.to_i record = load_target.detect { |record| id == record.id } - expects_array? ? [record] : record + expects_array ? [record] : record else load_target.select { |record| ids.include?(record.id) } end @@ -95,10 +95,9 @@ module ActiveRecord end protected - def find_target(sql = nil) - - if sql - records = @association_class.find_by_sql(sql) if sql + def find_target + if @options[:finder_sql] + records = @association_class.find_by_sql(@finder_sql) else records = find(:all) end -- cgit v1.2.3