diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-07-12 06:01:23 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-07-20 14:58:33 +0900 |
commit | 1a10d38d465b4f8843ec916538ad0fc70a890f4d (patch) | |
tree | e1ad35407a27933f0b133f0e484906f2a06b6a55 | |
parent | a8a3a8cc691facad4ba7487a7b66362b498720c9 (diff) | |
download | rails-1a10d38d465b4f8843ec916538ad0fc70a890f4d.tar.gz rails-1a10d38d465b4f8843ec916538ad0fc70a890f4d.tar.bz2 rails-1a10d38d465b4f8843ec916538ad0fc70a890f4d.zip |
Add `exists?` and `update_all` to `CollectionProxy` for respects an association scope
Fixes #25732.
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 20 |
2 files changed, 21 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 17ccf5a86c..db3037d8f9 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -29,7 +29,7 @@ module ActiveRecord # 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 @@ module ActiveRecord !!@association.include?(record) end - def arel #:nodoc: - scope.arel - end - def proxy_association @association end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 61a5c2c3b7..325a06d724 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -439,6 +439,26 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 |