Persist Deleted Records for Mongoid Soft delete functionality for Mongoid ORM so you may recover records at later stage.
Add following line to your Gemfile
gem 'persistable_mongoid' or gem 'persistable_mongoid', git: 'https://github.com/mshahzadtariq/persistable_mongoid' or gem install persistable_mongoid
And include this module to the model for which you want to enable soft delete and recovery feature
class MyModel include Mongoid::Document include MST::Persistable ...... end
and that is all.
Persist sensitive data with options to recover data.
To persist record, call destroy method on object. It will not delete record from database but persist that so you can recover it in the future if required.
object.destroy
It also has two scopes
only_deleted: Fetch only deleted records of that particular model e.g
Model.only_deleted
with_deleted: Fetch all records of that particular model including deleted records e.g
Model.with_deleted
To recover records, call recover method on object
Model.only_deleted.first.recover
To permanently delete record from system/database, call delete method
object.delete
-
Fork it
-
Create your feature branch (‘git checkout -b my-new-feature`)
-
Commit your changes (‘git commit -am ’Added some feature’‘)
-
Push to the branch (‘git push origin my-new-feature`)
-
Create new Pull Request