aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb2
-rwxr-xr-xactiverecord/test/associations_test.rb11
-rw-r--r--activerecord/test/fixtures/project.rb3
4 files changed, 12 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 056c1bf2eb..b91fb6213a 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Corrected typo in find SQL for has_and_belongs_to_many. #1312 [ben@bensinclair.com]
+
* Added ActiveRecord::Recursion for guarding against recursive saves
* Fixed sanitized conditions for has_many finder method. #1281 [jackc@hylesanderson.com, pragdave, Tobias Luetke]
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 f827cf3282..42a4f3495d 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
@@ -66,7 +66,7 @@ module ActiveRecord
# Otherwise, construct a query.
else
ids_list = ids.map { |id| @owner.send(:quote, id) }.join(',')
- records = find_target(@finder_sql.sub(/(ORDER BY|$)/, "AND j.#{@association_foreign_key} IN (#{ids_list}) \\1"))
+ records = find_target(@finder_sql.sub(/(ORDER BY|$)/, " AND j.#{@association_foreign_key} IN (#{ids_list}) \\1"))
if records.size == ids.size
if ids.size == 1 and !expects_array
records.first
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 043fe9e2fb..80b984722a 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -787,7 +787,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
end
def test_adding_multiple
- aredridel = Developer.new("name" => "Aridridel")
+ aredridel = Developer.new("name" => "Aredridel")
aredridel.save
aredridel.projects.reload
aredridel.projects.push(Project.find(1), Project.find(2))
@@ -796,7 +796,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
end
def test_adding_a_collection
- aredridel = Developer.new("name" => "Aridridel")
+ aredridel = Developer.new("name" => "Aredridel")
aredridel.save
aredridel.projects.reload
aredridel.projects.concat([Project.find(1), Project.find(2)])
@@ -807,7 +807,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
def test_habtm_adding_before_save
no_of_devels = Developer.count
no_of_projects = Project.count
- aredridel = Developer.new("name" => "Aridridel")
+ aredridel = Developer.new("name" => "Aredridel")
aredridel.projects.concat([Project.find(1), p = Project.new("name" => "Projekt")])
assert aredridel.new_record?
assert p.new_record?
@@ -947,7 +947,10 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
def test_associations_with_conditions
assert_equal 2, projects(:active_record).developers.size
assert_equal 1, projects(:active_record).developers_named_david.size
-
+
+ assert_equal developers(:david), projects(:active_record).developers_named_david.find(developers(:david).id)
+ assert_equal developers(:david), projects(:active_record).salaried_developers.find(developers(:david).id)
+
projects(:active_record).developers_named_david.clear
assert_equal 1, projects(:active_record, :reload).developers.size
end
diff --git a/activerecord/test/fixtures/project.rb b/activerecord/test/fixtures/project.rb
index 89d5c36db8..a40aca95e4 100644
--- a/activerecord/test/fixtures/project.rb
+++ b/activerecord/test/fixtures/project.rb
@@ -1,6 +1,7 @@
class Project < ActiveRecord::Base
has_and_belongs_to_many :developers, :uniq => true
has_and_belongs_to_many :developers_named_david, :class_name => "Developer", :conditions => "name = 'David'", :uniq => true
+ has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0"
has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => "DELETE FROM developers_projects WHERE project_id = \#{id} AND developer_id = \#{record.id}"
end
@@ -8,4 +9,4 @@ class SpecialProject < Project
def hello_world
"hello there!"
end
-end \ No newline at end of file
+end