开发者

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 s开发者_运维技巧till 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.


Found the answer:

whatever.save :validate => false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜