开发者

ignore before_update when save

开发者 https://www.devze.com 2023-01-20 17:11 出处:网络
some case I don\'t want execute before_update. please help me. case A: in case I want used before_update

some case I don't want execute before_update. please help me.

case A: in case I want used before_update

obj = 开发者_StackOverflowObject.find(id)
obj.save

but case B I don't want used before_update

obj = Object.find(id)
obj.save # in case I want used before_update


The method #save accepts a Hash of option. To skip validations:

obj.save(:validate => false)

This is the documented way to skip validations using the public API. Don't try to use send to call internal methods or your application might not work in the future.


update_without_callbacks and create_without_callbacks are private methods. These methods will not call any callbacks.

obj = Object.find(id)
obj.send(:update_without_callbacks)

obj = Object.new(:name => 'foo')
obj.send(:create_without_callbacks)
0

精彩评论

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