Browse files

Fix eager loading with pre-quoted table names. Closes #11046 [danielm…

…orrison, Koz, Jeremy Kemper]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8856 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c9402b2 commit d4daf7bba7dda756ab4700016e9b4b31f6127a1e @NZKoz NZKoz committed Feb 11, 2008
View
4 activerecord/lib/active_record/associations.rb
@@ -1379,7 +1379,7 @@ def include_eager_conditions?(options)
end
end
return false unless conditions.any?
- conditions.join(' ').scan(/([\.\w]+)\.\w+/).flatten.any? do |condition_table_name|
+ conditions.join(' ').scan(/([\.\w]+).?\./).flatten.any? do |condition_table_name|
condition_table_name != table_name
end
end
@@ -1388,7 +1388,7 @@ def include_eager_conditions?(options)
def include_eager_order?(options)
order = options[:order]
return false unless order
- order.to_s.scan(/([\.\w]+)\.\w+/).flatten.any? do |order_table_name|
+ order.to_s.scan(/([\.\w]+).?\./).flatten.any? do |order_table_name|
order_table_name != table_name
end
end
View
24 activerecord/test/cases/associations/eager_test.rb
@@ -119,6 +119,30 @@ def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_cond
assert_equal [6,7,8], comments.collect { |c| c.id }
end
+ def test_eager_association_loading_with_belongs_to_and_conditions_string_with_unquoted_table_name
+ assert_nothing_raised do
+ Comment.find(:all, :include => :post, :conditions => ['posts.id = ?',4])
+ end
+ end
+
+ def test_eager_association_loading_with_belongs_to_and_conditions_string_with_quoted_table_name
+ assert_nothing_raised do
+ Comment.find(:all, :include => :post, :conditions => ["#{Comment.connection.quote_table_name('posts.id')} = ?",4])
+ end
+ end
+
+ def test_eager_association_loading_with_belongs_to_and_order_string_with_unquoted_table_name
+ assert_nothing_raised do
+ Comment.find(:all, :include => :post, :order => 'posts.id')
+ end
+ end
+
+ def test_eager_association_loading_with_belongs_to_and_order_string_with_quoted_table_name
+ assert_nothing_raised do
+ Comment.find(:all, :include => :post, :order => Comment.connection.quote_table_name('posts.id'))
+ end
+ end
+
def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations
posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1, :order => 'posts.id')
assert_equal 1, posts.length

0 comments on commit d4daf7b

Please sign in to comment.