Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14124 from arthurnn/fix_14116

Fix collection proxy exists? regression
  • Loading branch information...
commit e5a6e6f1d8d2b15b31af4078c6373ef1680f8c23 2 parents b078f5e + f96831e
@tenderlove tenderlove authored
View
6 activerecord/lib/active_record/associations/collection_association.rb
@@ -24,10 +24,6 @@ module Associations
# 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 @@ def reader(force_reload = false)
reload
end
- @proxy
+ @proxy ||= CollectionProxy.create(klass, self)
end
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
View
7 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -817,6 +817,13 @@ def test_collection_create_with_nonstandard_primary_key_on_belongs_to
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")

0 comments on commit e5a6e6f

Please sign in to comment.
Something went wrong with that request. Please try again.