How to “update_attributes” without executing “before_save”?

前端 未结 5 770
小蘑菇
小蘑菇 2020-12-15 04:58

I have a before_save in my Message model defined like this:

   class Message < ActiveRecord::Base
     before_save lambda { foo(         


        
5条回答
  •  伪装坚强ぢ
    2020-12-15 05:42

    update_all won't trigger callbacks

    my_message.update_all(:created_at => ...)
    # OR
    Message.update_all({:created_at => ...}, {:id => my_message.id})
    

    http://apidock.com/rails/ActiveRecord/Base/update_all/class

提交回复
热议问题