提交 b1d48d54 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #25786 from kamipo/add_exists_and_update_all_to_collection_proxy

Add `exists?` and `update_all` to `CollectionProxy` for respects an association scope
......@@ -29,7 +29,7 @@ module Associations
# instantiation of the actual post records.
class CollectionProxy < Relation
delegate(*(ActiveRecord::Calculations.public_instance_methods - [:count]), to: :scope)
delegate :find_nth, to: :scope
delegate :find_nth, :exists?, :update_all, :arel, to: :scope
def initialize(klass, association) #:nodoc:
@association = association
......@@ -897,10 +897,6 @@ def include?(record)
!!@association.include?(record)
end
def arel #:nodoc:
scope.arel
end
def proxy_association
@association
end
......
......@@ -439,6 +439,26 @@ def test_create_resets_cached_counters
assert_equal person, person.readers.first.person
end
def test_update_all_respects_association_scope
person = Person.new
person.first_name = 'Naruto'
person.references << Reference.new
person.id = 10
person.references
person.save!
assert_equal 1, person.references.update_all(favourite: true)
end
def test_exists_respects_association_scope
person = Person.new
person.first_name = 'Sasuke'
person.references << Reference.new
person.id = 10
person.references
person.save!
assert_predicate person.references, :exists?
end
def force_signal37_to_load_all_clients_of_firm
companies(:first_firm).clients_of_firm.each {|f| }
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册