Mongoid dependent :destroy vs :delete

Matteo Pagliazzi picture Matteo Pagliazzi · Mar 31, 2012 · Viewed 8.9k times · Source

When using Mongoid referenced reletions what's the diffrence between dependent detroy and dependent delete since in the docs it tells:

:delete: Delete the child documents.
:destroy: Destroy the child documents.

Answer

Jeff Smith picture Jeff Smith · Mar 31, 2012

In Mongoid (and also ActiveRecord I believe), delete just removes the object from the database. destroy will delete the object and run all of the appropriate callbacks that the model has defined. So if you have a before_destroy callback on a model and you delete an instance of that model, the before_destroy callback will not be called.

So dependent: :destroy runs the model's callbacks when deleting and dependent: :delete does not.