aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Cochran <sj26@sj26.com>2012-10-05 14:22:50 +0800
committerSamuel Cochran <sj26@sj26.com>2012-10-05 14:25:20 +0800
commit2e05146c78b9af0c462f334174d4bb932e4183ff (patch)
tree30e25bd1529da506a70ec23b8729eaf4ddd4a8ea
parentec57489160a0eb7a50cd456e265ad08a228a5f30 (diff)
downloadrails-2e05146c78b9af0c462f334174d4bb932e4183ff.tar.gz
rails-2e05146c78b9af0c462f334174d4bb932e4183ff.tar.bz2
rails-2e05146c78b9af0c462f334174d4bb932e4183ff.zip
Add CollectionAssociation#destroy to association guide
-rw-r--r--guides/source/association_basics.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index dbf18b511c..42c7c07745 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -1130,6 +1130,7 @@ When you declare a `has_many` association, the declaring class automatically gai
* `collection(force_reload = false)`
* `collection<<(object, ...)`
* `collection.delete(object, ...)`
+* `collection.destroy(object, ...)`
* `collection=objects`
* `collection_singular_ids`
* `collection_singular_ids=ids`
@@ -1156,6 +1157,7 @@ Each instance of the customer model will have these methods:
orders(force_reload = false)
orders<<(object, ...)
orders.delete(object, ...)
+orders.destroy(object, ...)
orders=objects
order_ids
order_ids=ids
@@ -1195,6 +1197,15 @@ The `collection.delete` method removes one or more objects from the collection b
WARNING: Additionally, objects will be destroyed if they're associated with `:dependent => :destroy`, and deleted if they're associated with `:dependent => :delete_all`.
+##### `collection.destroy(object, ...)`
+
+The `collection.destroy` method removes one or more objects from the collection by running `destroy` on each object.
+
+```ruby
+@customer.orders.destroy(@order1)
+```
+
+WARNING: Objects will _always_ be removed from the database, ignoring the `:dependent` option.
##### `collection=objects`
@@ -1564,6 +1575,7 @@ When you declare a `has_and_belongs_to_many` association, the declaring class au
* `collection(force_reload = false)`
* `collection<<(object, ...)`
* `collection.delete(object, ...)`
+* `collection.destroy(object, ...)`
* `collection=objects`
* `collection_singular_ids`
* `collection_singular_ids=ids`
@@ -1590,6 +1602,7 @@ Each instance of the part model will have these methods:
assemblies(force_reload = false)
assemblies<<(object, ...)
assemblies.delete(object, ...)
+assemblies.destroy(object, ...)
assemblies=objects
assembly_ids
assembly_ids=ids
@@ -1636,6 +1649,16 @@ The `collection.delete` method removes one or more objects from the collection b
@part.assemblies.delete(@assembly1)
```
+WARNING: This does not trigger callbacks on the join records.
+
+##### `collection.destroy(object, ...)`
+
+The `collection.destroy` method removes one or more objects from the collection by running `destroy` on each record in the join table, including running callbacks. This does not destroy the objects.
+
+```ruby
+@part.assemblies.destroy(@assembly1)
+```
+
##### `collection=objects`
The `collection=` method makes the collection contain only the supplied objects, by adding and deleting as appropriate.