aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations/eager_test.rb5
-rw-r--r--activerecord/test/fixtures/author.rb2
2 files changed, 6 insertions, 1 deletions
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
diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb
index 1503e17f87..538ed7ac7f 100644
--- a/activerecord/test/fixtures/author.rb
+++ b/activerecord/test/fixtures/author.rb
@@ -105,5 +105,5 @@ end
class AuthorFavorite < ActiveRecord::Base
belongs_to :author
- belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id'
+ belongs_to :favorite_author, :class_name => "Author"
end