how rails “update” multiple columns correctly - (updated_at should be updated as well)

后端 未结 3 1558
忘了有多久
忘了有多久 2021-01-21 06:06

I am having trouble updating multiple columns properly with rails activerecords. I want to use something like update which basically gets updated_at updated, but i just cant pas

3条回答
  •  心在旅途
    2021-01-21 06:22

    Updates all, This method constructs a single SQL UPDATE statement and sends it straight to the database. It does not instantiate the involved models and it does not trigger Active Record callbacks or validations. Values passed to update_all will not go through ActiveRecord's type-casting behavior. It should receive only values that can be passed as-is to the SQL database.

    As such, it does not trigger callbacks nor validations - and timestamp update is made in a callback.update_at is a call back

提交回复
热议问题