2

Mongoid supports soft deletion with

include Mongoid::Paranoia

Lets suppose i have soft deleted a document from one of the collection.

Now I need a query that includes a soft deleted document from that collection.

How can I do that?

Do I need to make a separate method for this to achieve?

Thanks

Gagan
  • 4,278
  • 7
  • 46
  • 71

1 Answers1

-1

You can find all deleted documents by query

 Model.deleted

and if you want to find deleted documents with specific condition then

 Model.deleted.where(:field => value)
abhas
  • 5,193
  • 1
  • 32
  • 56
  • No you didn't get my question. Your query just does query on deleted documents in a collection. What I need is a query that includes both deleted and not deleted documents with a condition. – Gagan May 24 '12 at 11:38
  • you have to run the condition on deleted documents like i mentioned and on non deleted then join them to get the result. – abhas May 24 '12 at 11:47
  • No I dont want to query twice for my condition. Is there any way out for my condition so that i can get both deleted and not deleted documents in one query. thanks – Gagan May 24 '12 at 11:49
  • 1
    srry for the answer actually i found a better solution i think u can check here http://stackoverflow.com/questions/7357947/rails-mongoid-clear-criteria – abhas May 24 '12 at 11:50
  • as per https://github.com/mongoid/mongoid/issues/1064, you should not need any hacks for this now. using `Model.unscoped` should work just fine. – rubish May 24 '12 at 12:00