Method: Mongoid::Association::Embedded::EmbedsMany::Proxy#clear

Defined in:
lib/mongoid/association/embedded/embeds_many/proxy.rb

#clearself

Clear the association. Will delete the documents from the db if they are already persisted.

If the host document is not persisted but its _id matches a persisted document, calling #clear on an association will remove the association’s documents from the database even though the set of documents in the application (as loaded in the host) is different from what is in the database, and the host may not contain any persisted documents in the association either.

Examples:

Clear the association.

person.addresses.clear

Returns:

  • (self)

    The empty association.



168
169
170
171
172
# File 'lib/mongoid/association/embedded/embeds_many/proxy.rb', line 168

def clear
  batch_clear(_target.dup)
  update_attributes_hash
  self
end