diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-20 09:59:29 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-20 09:59:29 -0800 |
commit | e5a6e6f1d8d2b15b31af4078c6373ef1680f8c23 (patch) | |
tree | 5dab03a74ed638a9aca92738d6a44fe53d11fd15 /activerecord | |
parent | b078f5ed843f23c61412ab21a94613377c9ad052 (diff) | |
parent | f96831e5ec200d957265adb7df765214123fbd6e (diff) | |
download | rails-e5a6e6f1d8d2b15b31af4078c6373ef1680f8c23.tar.gz rails-e5a6e6f1d8d2b15b31af4078c6373ef1680f8c23.tar.bz2 rails-e5a6e6f1d8d2b15b31af4078c6373ef1680f8c23.zip |
Merge pull request #14124 from arthurnn/fix_14116
Fix collection proxy exists? regression
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 7 |
2 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 03ca00fa70..89b7945c78 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -24,10 +24,6 @@ module ActiveRecord # If you need to work on all current children, new and existing records, # +load_target+ and the +loaded+ flag are your friends. class CollectionAssociation < Association #:nodoc: - def initialize(owner, reflection) - super - @proxy = CollectionProxy.create(klass, self) - end # Implements the reader method, e.g. foo.items for Foo.has_many :items def reader(force_reload = false) @@ -37,7 +33,7 @@ module ActiveRecord reload end - @proxy + @proxy ||= CollectionProxy.create(klass, self) end # Implements the writer method, e.g. foo.items= for Foo.has_many :items 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 47592f312e..026a7fe635 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -817,6 +817,13 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert author.named_categories(true).include?(category) end + def test_collection_exists + author = authors(:mary) + category = Category.create!(author_ids: [author.id], name: "Primary") + assert category.authors.exists?(id: author.id) + assert category.reload.authors.exists?(id: author.id) + end + def test_collection_delete_with_nonstandard_primary_key_on_belongs_to author = authors(:mary) category = author.named_categories.create(:name => "Primary") |