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.
# File activerecord/lib/active_record/associations/collection_association.rb, line 216
def delete(*records)
dependent = options[:dependent]
if records.first == :all
if dependent && dependent == :destroy
message = 'In Rails 4.1 delete_all on associations would not fire callbacks. ' 'It means if the :dependent option is :destroy then the associated ' 'records would be deleted without loading and invoking callbacks.'
ActiveRecord::Base.logger ? ActiveRecord::Base.logger.warn(message) : $stderr.puts(message)
end
if loaded? || dependent == :destroy
delete_or_destroy(load_target, dependent)
else
delete_records(:all, dependent)
end
else
records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
delete_or_destroy(records, dependent)
end
end