What is covered by save(:validate => false)?

与世无争的帅哥 提交于 2019-12-05 11:11:12

If you pass in the :validate=>false, it skips the valid? command. Everything else functions the same.

You can check the code out here: http://api.rubyonrails.org/classes/ActiveRecord/Validations.html

def save(options={})
  perform_validations(options) ? super : false
end

...

if perform_validation
  valid?(options.is_a?(Hash) ? options[:context] : nil)
else
  true
end

Testing on Rails 4.2.6 shows that .save(:validate=>false) will actually skip before_validations and after_validation callbacks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!