diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-08-15 16:00:35 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-08-15 16:01:01 +0100 |
commit | 57423d815b3747aa382cd3859a15bffa538525ad (patch) | |
tree | 4ab80289139009b5476db1b62253fb034af56205 /activerecord/test/cases | |
parent | 4c743d9fceabc254a6e5e92412753b31fb0a24ff (diff) | |
download | rails-57423d815b3747aa382cd3859a15bffa538525ad.tar.gz rails-57423d815b3747aa382cd3859a15bffa538525ad.tar.bz2 rails-57423d815b3747aa382cd3859a15bffa538525ad.zip |
Ensure empty has_many :through association preloaded via joins is marked as loaded. Fixes #2054.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 0b1ba31ac2..5f2328ff95 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -813,4 +813,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert !c.save end end + + def test_preloading_empty_through_association_via_joins + person = Person.create!(:first_name => "Gaga") + person = Person.where(:id => person.id).where('readers.id = 1 or 1=1').includes(:posts).to_a.first + + assert person.posts.loaded?, 'person.posts should be loaded' + assert_equal [], person.posts + end end |