From f6379bfe154087bf93e1546bb7626941c77e9da7 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 21 Dec 2007 01:49:01 +0000 Subject: Eager belongs_to :include infers the foreign key from the association name rather than the class name. Closes #10517. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8456 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations/eager_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/associations/eager_test.rb') diff --git a/activerecord/test/associations/eager_test.rb b/activerecord/test/associations/eager_test.rb index 4fc2e62842..69b1584b63 100644 --- a/activerecord/test/associations/eager_test.rb +++ b/activerecord/test/associations/eager_test.rb @@ -115,6 +115,11 @@ class EagerAssociationTest < Test::Unit::TestCase assert_equal [2], posts.collect { |p| p.id } end + def test_eager_association_loading_with_belongs_to_inferred_foreign_key_from_association_name + author_favorite = AuthorFavorite.find(:first, :include => :favorite_author) + assert_equal authors(:mary), assert_no_queries { author_favorite.favorite_author } + end + def test_eager_association_loading_with_explicit_join posts = Post.find(:all, :include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id') assert_equal 1, posts.length -- cgit v1.2.3