diff options
author | Xavier Noria <fxn@hashref.com> | 2008-10-17 02:04:50 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2008-10-17 02:04:50 +0200 |
commit | 4ab8c087e778d746f9a3a0b4f8086ca262c5fcad (patch) | |
tree | 1390885a6772a984313c9820720f58fbce81707f | |
parent | 2636807dfbec2f0bf68fe3afe5df45eedeb88663 (diff) | |
download | rails-4ab8c087e778d746f9a3a0b4f8086ca262c5fcad.tar.gz rails-4ab8c087e778d746f9a3a0b4f8086ca262c5fcad.tar.bz2 rails-4ab8c087e778d746f9a3a0b4f8086ca262c5fcad.zip |
revised documentation of collection.delete
4 files changed, 12 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index ad093d83d4..187caa13d0 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -624,7 +624,8 @@ module ActiveRecord # 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] diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 09a80be266..da1a7887ce 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -183,7 +183,13 @@ module ActiveRecord 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) } diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 3b2f306637..3348079e9d 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -61,6 +61,7 @@ module ActiveRecord record.save end + # Deletes the records according to the <tt>:dependent</tt> option. def delete_records(records) case @reflection.options[:dependent] when :destroy diff --git a/railties/doc/guides/activerecord/association_basics.txt b/railties/doc/guides/activerecord/association_basics.txt index df89cfb531..695b834652 100644 --- a/railties/doc/guides/activerecord/association_basics.txt +++ b/railties/doc/guides/activerecord/association_basics.txt @@ -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+ |