diff options
author | Frederick Cheung <frederick.cheung@gmail.com> | 2008-05-02 00:00:42 +0100 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-05-06 21:08:52 +1200 |
commit | fbebdb0c091c37b0bc75ab774d187d8bc8795bd2 (patch) | |
tree | ce0267cb79b2f960b71a336598b14ee828b55460 /activerecord/test | |
parent | a08004a9a7d4c93c39f9693f6406ecb70d6a38c0 (diff) | |
download | rails-fbebdb0c091c37b0bc75ab774d187d8bc8795bd2.tar.gz rails-fbebdb0c091c37b0bc75ab774d187d8bc8795bd2.tar.bz2 rails-fbebdb0c091c37b0bc75ab774d187d8bc8795bd2.zip |
Ensure correct record is returned when preloading has_one where more than one row exists
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#73 state:closed]
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 2 |
2 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 546ed80894..67b57ceb42 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -29,6 +29,10 @@ class EagerAssociationTest < ActiveRecord::TestCase post = Post.find(:first, :include => :comments, :conditions => "posts.title = 'Welcome to the weblog'") assert_equal 2, post.comments.size assert post.comments.include?(comments(:greetings)) + + posts = Post.find(:all, :include => :last_comment) + post = posts.find { |p| p.id == 1 } + assert_equal Post.find(1).last_comment, post.last_comment end def test_loading_conditions_with_or diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 22c5a645b8..d9101706b5 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -9,6 +9,8 @@ class Post < ActiveRecord::Base belongs_to :author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts + has_one :last_comment, :class_name => 'Comment', :order => 'id desc' + has_many :comments, :order => "body" do def find_most_recent find(:first, :order => "id DESC") |