Permalink
Browse files

revised documentation of collection.delete

  • Loading branch information...
1 parent 2636807 commit 4ab8c087e778d746f9a3a0b4f8086ca262c5fcad @fxn fxn committed Oct 17, 2008
@@ -624,7 +624,8 @@ module ClassMethods
# Adds one or more objects to the collection by setting their foreign keys to the collection's primary key.
# [collection.delete(object, ...)]
# Removes one or more objects from the collection by setting their foreign keys to +NULL+.
- # This will also destroy the objects if they're declared as +belongs_to+ and dependent on this model.
+ # Objects will be in addition destroyed if they're associated with <tt>:dependent => :destroy</tt>,
+ # and deleted if they're associated with <tt>:dependent => :delete_all</tt>.
# [collection=objects]
# Replaces the collections content by deleting and adding objects as appropriate.
# [collection_singular_ids]
@@ -183,7 +183,13 @@ def count(*args)
end
- # Remove +records+ from this association. Does not destroy +records+.
+ # Removes +records+ from this association calling +before_remove+ and
+ # +after_remove+ callbacks.
+ #
+ # This method is abstract in the sense that +delete_records+ has to be
+ # provided by descendants. Note this method does not imply the records
+ # are actually removed from the database, that depends precisely on
+ # +delete_records+. They are in any case removed from the collection.
def delete(*records)
records = flatten_deeper(records)
records.each { |record| raise_on_type_mismatch(record) }
@@ -61,6 +61,7 @@ def insert_record(record)
record.save
end
+ # Deletes the records according to the <tt>:dependent</tt> option.
def delete_records(records)
case @reflection.options[:dependent]
when :destroy
@@ -1085,7 +1085,8 @@ The +_collection_.delete+ method removes one or more objects from the collection
@customer.orders.delete(@order1)
-------------------------------------------------------
-WARNING: The +_collection_.delete+ method will destroy the deleted object if they are declared as +belongs_to+ and are dependent on this model.
+WARNING: Objects will be in addition destroyed if they're associated with +:dependent => :destroy+, and deleted if they're associated with +:dependent => :delete_all+.
+
===== +_collection_=objects+

0 comments on commit 4ab8c08

Please sign in to comment.