保存时忽略 before_update
某些情况下我不想执行 before_update。请帮我。
情况 A:如果我想使用 before_update
obj = Object.find(id)
obj.save
但情况 BI 不想使用 before_update
obj = Object.find(id)
obj.save # 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 = Object.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方法
#save
接受选项的哈希值。跳过验证:这是使用公共 API 跳过验证的记录方法。不要尝试使用 send 来调用内部方法,否则您的应用程序将来可能无法工作。
The method
#save
accepts a Hash of option. To skip validations: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 和 create_without_callbacks 是私有方法。这些方法不会调用任何回调。
update_without_callbacks and create_without_callbacks are private methods. These methods will not call any callbacks.