Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoMapper: How do you save a model instance bypassing validations but not callbacks?

Is there a way to save a MongoMapper model instance such that validations are not performed but callbacks are called? This would be analagous to ActiveRecord's whatever.save(false)

I found a snippet of code online that can be used to bypasses both validations and callbacks:

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

So if there is an easy way to also manually run callbacks, I could use that along with the above snippet above to do it. But that would still be an inelegant and verbose way to do something relatively simple -- I'm hoping there is a simple way build into the API to skip just validations.

like image 325
Ben Lee Avatar asked Apr 29 '11 20:04

Ben Lee


1 Answers

Found the answer:

whatever.save :validate => false
like image 88
Ben Lee Avatar answered Oct 29 '22 04:10

Ben Lee