Update_all or update_attribute doesn't update the column

五迷三道 提交于 2019-12-06 15:28:13

This is because update_all sends an update directly to the database - it won't update the report models you have in memory. If you check the database after running your current version, you'll see that the records have been updated.

You need to call 'reload' on each report to get the updated version from the database or

reports.map(&:reload)

to do them all in one go.

If update_all or update_attribute does not work you can use this

reports.update_attributes(:sent_mail => true)
Salil

Ref update_all, update_attributes and update_attribute

Change

reports.update_all(sent_mail: true)

To

reports.update_attribute('sent_mail', true)

There is difference between update_attribute and update_attributes update_attribute vs update_attributes

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