aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-13 10:15:54 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-13 10:15:54 +0000
commit4307d7ecbe897880a59ae2da717a893ccf0f3fde (patch)
tree95d6f039e1f3bf95aa5fc76ef06698fbb44b1d35 /activerecord/lib/active_record/associations
parent6a0e41c158d327967e75fc93f001452449e8afe1 (diff)
downloadrails-4307d7ecbe897880a59ae2da717a893ccf0f3fde.tar.gz
rails-4307d7ecbe897880a59ae2da717a893ccf0f3fde.tar.bz2
rails-4307d7ecbe897880a59ae2da717a893ccf0f3fde.zip
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
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb11
1 files changed, 5 insertions, 6 deletions
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