MongoMapper: How to save an instance of a model, bypassing checks, but not callbacks?

Is there a way to save an instance of the MongoMapper model so that checks are not performed, but callbacks are called? This would be similar to ActiveRecord whatever.save(false)

I found a piece of code online that can be used to circumvent both checks and callbacks:

 doc = whatever.to_mongo Whatever.collection.save(doc, :safe => true) 

So, if there is an easy way to also manually trigger callbacks, I could use this along with the above snippet to do this. But it will still be an inelegant and verbose way to do something relatively simple - I hope the API has an easy way to skip only the checks.

+6
source share
1 answer

Found answer:

 whatever.save :validate => false 
+5
source

Source: https://habr.com/ru/post/886983/


All Articles