aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/eager_test.rb
diff options
context:
space:
mode:
authorTarmo Tänav <tarmo@itech.ee>2008-08-26 03:01:24 +0300
committerJeremy Kemper <jeremy@bitsweat.net>2008-08-25 21:23:35 -0700
commita445cdd8840c4e99c40c6d5b15ab380d39a56be3 (patch)
tree1d9e7ee98e9607fd635f1743fa6c6bf507ba297e /activerecord/test/cases/associations/eager_test.rb
parent2dbda11945507a0541d61d13b8c564121c1cd362 (diff)
downloadrails-a445cdd8840c4e99c40c6d5b15ab380d39a56be3.tar.gz
rails-a445cdd8840c4e99c40c6d5b15ab380d39a56be3.tar.bz2
rails-a445cdd8840c4e99c40c6d5b15ab380d39a56be3.zip
Load the first and not the last has_one result when doing join-based eager loading
This matters when the has_one is defined with an order in which case there is an expectation that the first one will be loaded. [#904 state:resolved] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test/cases/associations/eager_test.rb')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index f37e18df35..956a2891aa 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -38,6 +38,12 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal Post.find(1).last_comment, post.last_comment
end
+ def test_loading_with_one_association_with_non_preload
+ posts = Post.find(:all, :include => :last_comment, :order => 'comments.id DESC')
+ post = posts.find { |p| p.id == 1 }
+ assert_equal Post.find(1).last_comment, post.last_comment
+ end
+
def test_loading_conditions_with_or
posts = authors(:david).posts.find(:all, :include => :comments, :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE} = 'SpecialComment'")
assert_nil posts.detect { |p| p.author_id != authors(:david).id },