aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-04-20 13:51:11 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-04-20 13:51:11 +0100
commit489abfd3b23f3c4b3de86aeb3bde3970771c001b (patch)
tree49eb51b0702d088302cf592b99c391528246fc96 /activerecord/test
parent7ce0778a1516110cf8015e59e2e8fac15032379c (diff)
downloadrails-489abfd3b23f3c4b3de86aeb3bde3970771c001b.tar.gz
rails-489abfd3b23f3c4b3de86aeb3bde3970771c001b.tar.bz2
rails-489abfd3b23f3c4b3de86aeb3bde3970771c001b.zip
Ensure JoinAssociation uses aliased table name when multiple associations have hash conditions on the same table
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/inner_join_association_test.rb5
-rw-r--r--activerecord/test/models/author.rb2
2 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb
index f87c914125..7141531740 100644
--- a/activerecord/test/cases/associations/inner_join_association_test.rb
+++ b/activerecord/test/cases/associations/inner_join_association_test.rb
@@ -29,6 +29,11 @@ class InnerJoinAssociationTest < ActiveRecord::TestCase
assert_match /INNER JOIN .?categories.? ON.*AND.*.?General.?.*TERMINATING_MARKER/, sql
end
+ def test_construct_finder_sql_applies_aliases_tables_on_association_conditions
+ result = Author.find(:all, :joins => [:thinking_posts, :welcome_posts])
+ assert_equal authors(:david), result.first
+ end
+
def test_construct_finder_sql_unpacks_nested_joins
sql = Author.send(:construct_finder_sql, :joins => {:posts => [[:comments]]})
assert_no_match /inner join.*inner join.*inner join/i, sql, "only two join clauses should be present"
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb
index 4ffac4fe32..669c664bf4 100644
--- a/activerecord/test/models/author.rb
+++ b/activerecord/test/models/author.rb
@@ -25,6 +25,8 @@ class Author < ActiveRecord::Base
has_many :comments_with_order_and_conditions, :through => :posts, :source => :comments, :order => 'comments.body', :conditions => "comments.body like 'Thank%'"
has_many :comments_with_include, :through => :posts, :source => :comments, :include => :post
+ has_many :thinking_posts, :class_name => 'Post', :conditions => { :title => 'So I was thinking' }
+ has_many :welcome_posts, :class_name => 'Post', :conditions => { :title => 'Welcome to the weblog' }
has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1