diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-13 10:15:54 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-13 10:15:54 +0000 |
commit | 4307d7ecbe897880a59ae2da717a893ccf0f3fde (patch) | |
tree | 95d6f039e1f3bf95aa5fc76ef06698fbb44b1d35 /activerecord/test | |
parent | 6a0e41c158d327967e75fc93f001452449e8afe1 (diff) | |
download | rails-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/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 13 | ||||
-rw-r--r-- | activerecord/test/fixtures/project.rb | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 4eb6216dda..35e14a5e19 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -1145,6 +1145,19 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase assert_equal developers(:david), active_record.developers.find(developers(:david).id), "Ruby find" end + def test_find_in_association_with_custom_finder_sql + assert_equal developers(:david), projects(:active_record).developers_with_finder_sql.find(developers(:david).id), "SQL find" + + active_record = projects(:active_record) + active_record.developers_with_finder_sql.reload + assert_equal developers(:david), active_record.developers_with_finder_sql.find(developers(:david).id), "Ruby find" + end + + def test_find_in_association_with_custom_finder_sql_and_string_id + assert_equal developers(:david), projects(:active_record).developers_with_finder_sql.find(developers(:david).id.to_s), "SQL find" + end + + def test_new_with_values_in_collection jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis') david = DeveloperForProjectWithAfterCreateHook.find_by_name('David') diff --git a/activerecord/test/fixtures/project.rb b/activerecord/test/fixtures/project.rb index 9a13c9eead..f8519f1b8c 100644 --- a/activerecord/test/fixtures/project.rb +++ b/activerecord/test/fixtures/project.rb @@ -2,6 +2,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_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id}' 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}" has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id}"}, :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id}"}, |