Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add CollectionAssociation#destroy to association guide

  • Loading branch information...
commit 2e05146c78b9af0c462f334174d4bb932e4183ff 1 parent ec57489
Samuel Cochran authored October 05, 2012

Showing 1 changed file with 23 additions and 0 deletions. Show diff stats Hide diff stats

  1. 23  guides/source/association_basics.md
23  guides/source/association_basics.md
Source Rendered
@@ -1130,6 +1130,7 @@ When you declare a `has_many` association, the declaring class automatically gai
1130 1130
 * `collection(force_reload = false)`
1131 1131
 * `collection<<(object, ...)`
1132 1132
 * `collection.delete(object, ...)`
  1133
+* `collection.destroy(object, ...)`
1133 1134
 * `collection=objects`
1134 1135
 * `collection_singular_ids`
1135 1136
 * `collection_singular_ids=ids`
@@ -1156,6 +1157,7 @@ Each instance of the customer model will have these methods:
1156 1157
 orders(force_reload = false)
1157 1158
 orders<<(object, ...)
1158 1159
 orders.delete(object, ...)
  1160
+orders.destroy(object, ...)
1159 1161
 orders=objects
1160 1162
 order_ids
1161 1163
 order_ids=ids
@@ -1195,6 +1197,15 @@ The `collection.delete` method removes one or more objects from the collection b
1195 1197
 
1196 1198
 WARNING: Additionally, objects will be destroyed if they're associated with `:dependent => :destroy`, and deleted if they're associated with `:dependent => :delete_all`.
1197 1199
 
  1200
+##### `collection.destroy(object, ...)`
  1201
+
  1202
+The `collection.destroy` method removes one or more objects from the collection by running `destroy` on each object.
  1203
+
  1204
+```ruby
  1205
+@customer.orders.destroy(@order1)
  1206
+```
  1207
+
  1208
+WARNING: Objects will _always_ be removed from the database, ignoring the `:dependent` option.
1198 1209
 
1199 1210
 ##### `collection=objects`
1200 1211
 
@@ -1564,6 +1575,7 @@ When you declare a `has_and_belongs_to_many` association, the declaring class au
1564 1575
 * `collection(force_reload = false)`
1565 1576
 * `collection<<(object, ...)`
1566 1577
 * `collection.delete(object, ...)`
  1578
+* `collection.destroy(object, ...)`
1567 1579
 * `collection=objects`
1568 1580
 * `collection_singular_ids`
1569 1581
 * `collection_singular_ids=ids`
@@ -1590,6 +1602,7 @@ Each instance of the part model will have these methods:
1590 1602
 assemblies(force_reload = false)
1591 1603
 assemblies<<(object, ...)
1592 1604
 assemblies.delete(object, ...)
  1605
+assemblies.destroy(object, ...)
1593 1606
 assemblies=objects
1594 1607
 assembly_ids
1595 1608
 assembly_ids=ids
@@ -1636,6 +1649,16 @@ The `collection.delete` method removes one or more objects from the collection b
1636 1649
 @part.assemblies.delete(@assembly1)
1637 1650
 ```
1638 1651
 
  1652
+WARNING: This does not trigger callbacks on the join records.
  1653
+
  1654
+##### `collection.destroy(object, ...)`
  1655
+
  1656
+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.
  1657
+
  1658
+```ruby
  1659
+@part.assemblies.destroy(@assembly1)
  1660
+```
  1661
+
1639 1662
 ##### `collection=objects`
1640 1663
 
1641 1664
 The `collection=` method makes the collection contain only the supplied objects, by adding and deleting as appropriate.

0 notes on commit 2e05146

Please sign in to comment.
Something went wrong with that request. Please try again.