From 21e67d9d0bc8728e80d28013a4462fadef0a5f65 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Sat, 28 Jun 2008 11:33:45 +0200 Subject: [PATCH] Eager loading should fetch limited associated records --- .../lib/active_record/association_preload.rb | 2 +- activerecord/test/cases/associations/eager_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 49f5270..d64505a 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -104,7 +104,7 @@ module ActiveRecord :include => options[:include], :joins => "INNER JOIN #{connection.quote_table_name options[:join_table]} as t0 ON #{reflection.klass.quoted_table_name}.#{reflection.klass.primary_key} = t0.#{reflection.association_foreign_key}", :select => "#{options[:select] || table_name+'.*'}, t0.#{reflection.primary_key_name} as the_parent_record_id", - :order => options[:order]) + :order => options[:order], :limit => options[:limit]) set_association_collection_records(id_to_record_map, reflection.name, associated_records, 'the_parent_record_id') end diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index f65ada5..90afa1a 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -114,6 +114,11 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_nil Post.find(posts(:authorless).id, :include => :author).author end + def test_loading_should_fetch_limited_associated_records + assert_equal projects(:active_record).limited_developers.size, + Project.find(projects(:active_record).id, :include => :limited_developers).limited_developers.size + end + def test_nested_loading_with_no_associations assert_nothing_raised do Post.find(posts(:authorless).id, :include => {:author => :author_addresss}) -- 1.5.4.5