diff options
author | Piotr Jakubowski <piotrj@gmail.com> | 2016-01-20 21:53:17 +0100 |
---|---|---|
committer | Piotr Jakubowski <piotrj@gmail.com> | 2016-05-04 22:01:24 +0200 |
commit | eebcebdeb58ff7b6c05cb1cfbbc9aa4c85c9800e (patch) | |
tree | 2b7f9fb90a4171432ddd7751fd1599eeca930d15 /activerecord/test/cases/associations | |
parent | 8352c8c6ef58eef822947faf8defc378e5de057c (diff) | |
download | rails-eebcebdeb58ff7b6c05cb1cfbbc9aa4c85c9800e.tar.gz rails-eebcebdeb58ff7b6c05cb1cfbbc9aa4c85c9800e.tar.bz2 rails-eebcebdeb58ff7b6c05cb1cfbbc9aa4c85c9800e.zip |
When deleting through records, take into account association conditions
Fixes #18424.
When deleting through records, it didn't take into account the
conditions that may have been affecting join model table, but was
defined in association definition.
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 16 |
1 files changed, 16 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 aff0dabee7..888f1a14d1 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -1215,4 +1215,20 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase ensure TenantMembership.current_member = nil end + + def test_has_many_through_update_ids_with_conditions + author = Author.create :name => "Bill" + category = categories(:general) + author.update(special_categories_with_condition_ids: [category.id], + nonspecial_categories_with_condition_ids: [category.id]) + + assert_equal [category.id], author.special_categories_with_condition_ids + assert_equal [category.id], author.nonspecial_categories_with_condition_ids + + author.update(nonspecial_categories_with_condition_ids: []) + author.reload + + assert_equal [category.id], author.special_categories_with_condition_ids + assert_equal [], author.nonspecial_categories_with_condition_ids + end end |