aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-03-18 07:31:01 +0000
committerRick Olson <technoweenie@gmail.com>2006-03-18 07:31:01 +0000
commit229c0f4367be3c766886d75b51e3c15ee8916fc2 (patch)
tree47bcb766fefb4f808406f1ec8a1b52eb345b06b6 /activerecord/test
parentf1a350a05c97d6e54e6dde26c101e8035d55e40c (diff)
downloadrails-229c0f4367be3c766886d75b51e3c15ee8916fc2.tar.gz
rails-229c0f4367be3c766886d75b51e3c15ee8916fc2.tar.bz2
rails-229c0f4367be3c766886d75b51e3c15ee8916fc2.zip
Rework table aliasing to account for truncated table aliases. Add smarter table aliasing when doing eager loading of STI associations. This allows you to use the association name in the order/where clause. [Jonathan Viney / Rick Olson] closes #4108
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3921 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/adapter_test.rb14
-rw-r--r--activerecord/test/associations_cascaded_eager_loading_test.rb18
-rwxr-xr-xactiverecord/test/associations_test.rb2
3 files changed, 27 insertions, 7 deletions
diff --git a/activerecord/test/adapter_test.rb b/activerecord/test/adapter_test.rb
index 2c98045cee..af94904eee 100644
--- a/activerecord/test/adapter_test.rb
+++ b/activerecord/test/adapter_test.rb
@@ -47,16 +47,18 @@ class AdapterTest < Test::Unit::TestCase
end
def test_table_alias
- old = @connection.table_alias_length
- def @connection.table_alias_length() 10; end
+ def @connection.test_table_alias_length() 10; end
+ class << @connection
+ alias_method :old_table_alias_length, :table_alias_length
+ alias_method :table_alias_length, :test_table_alias_length
+ end
assert_equal 'posts', @connection.table_alias_for('posts')
- assert_equal 'posts', @connection.table_alias_for('posts', 1)
- assert_equal 'posts_2', @connection.table_alias_for('posts', 2)
assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
- assert_equal 'posts_co_2', @connection.table_alias_for('posts_comments', 2)
- def @connection.table_alias_length() old; end
+ class << @connection
+ alias_method :table_alias_length, :old_table_alias_length
+ end
end
# test resetting sequences in odd tables in postgreSQL
diff --git a/activerecord/test/associations_cascaded_eager_loading_test.rb b/activerecord/test/associations_cascaded_eager_loading_test.rb
index 8f0a41f593..166d2b2262 100644
--- a/activerecord/test/associations_cascaded_eager_loading_test.rb
+++ b/activerecord/test/associations_cascaded_eager_loading_test.rb
@@ -85,4 +85,22 @@ class CascadedEagerLoadingTest < Test::Unit::TestCase
assert_equal [topics(:second)], replies
assert_equal topics(:first), assert_no_queries { replies.first.topic }
end
+
+ def test_eager_association_loading_with_multiple_stis_and_order
+ author = Author.find(:first, :include => { :posts => [ :special_comments , :very_special_comment ] }, :order => 'authors.name, special_comments.body, very_special_comments.body', :conditions => 'posts.id = 4')
+ assert_equal authors(:david), author
+ assert_no_queries do
+ author.posts.first.special_comments
+ author.posts.first.very_special_comment
+ end
+ end
+
+ def test_eager_association_loading_of_stis_with_multiple_references
+ authors = Author.find(:all, :include => { :posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } } }, :order => 'special_comments.body, very_special_comments.body', :conditions => 'posts.id = 4')
+ assert_equal [authors(:david)], authors
+ assert_no_queries do
+ authors.first.posts.first.special_comments.first.post.special_comments
+ authors.first.posts.first.special_comments.first.post.very_special_comment
+ end
+ end
end
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 89d85bd567..6b5b8a8d70 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -1471,6 +1471,6 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
end
def test_join_table_alias
- assert_equal 3, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'join_project_developers.joined_on IS NOT NULL').size
+ assert_equal 3, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL').size
end
end