diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-06-03 00:30:54 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-06-03 00:30:54 -0300 |
commit | 814a994e1bfbb1a3a9cc94103e665ea90fafe792 (patch) | |
tree | 233e4064ee3de4ceea0265c607e7771998f9c7a5 /guides/source | |
parent | 8193a09a1f0f15c4b7624d6c24e8a779baa64d39 (diff) | |
parent | efa1648f282f3844656e5a89ea2207934bcb1130 (diff) | |
download | rails-814a994e1bfbb1a3a9cc94103e665ea90fafe792.tar.gz rails-814a994e1bfbb1a3a9cc94103e665ea90fafe792.tar.bz2 rails-814a994e1bfbb1a3a9cc94103e665ea90fafe792.zip |
Merge pull request #20421 from repinel/fix-clear-guides-and-related-api-docs
[ci skip] fix the `collection.clear` guide
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/association_basics.md | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index b9c9995a79..3f63c31cce 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -1467,7 +1467,13 @@ The `collection_singular_ids=` method makes the collection contain only the obje ##### `collection.clear` -The `collection.clear` method removes every object from the collection. This destroys the associated objects if they are associated with `dependent: :destroy`, deletes them directly from the database if `dependent: :delete_all`, and otherwise sets their foreign keys to `NULL`. +The `collection.clear` method removes all objects from the collection according to the strategy specified by the `dependent` option. If no option is given, it follows the default strategy. The default strategy for `has_many :through` associations is `delete_all`, and for `has_many` associations is to set the foreign keys to `NULL`. + +```ruby +@customer.orders.clear +``` + +WARNING: Objects will be delete if they're associated with `dependent: :destroy`, just like `dependent: :delete_all`. ##### `collection.empty?` |