和before_save:before_update活动记录回调之间的区别是什么? [英] What is the difference between the :before_save and :before_update Active Record callbacks?

查看:401
本文介绍了和before_save:before_update活动记录回调之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人请向我解释之间的差异:before_save :before_update 在Ruby中的Active Record回调轨道4?

Could someone please explain to me the difference between the :before_save and :before_update Active Record callbacks in Ruby on Rails 4?

我通过活动记录回调官方文档阅读,但我无法找到一个颗粒状足够的解释。

I read through the official documentation on Active Record callbacks, but I couldn't find a granular-enough explanation.

推荐答案

:before_save 被称为每次一个记录插入/在数据库中更新。因此,它被称为每次保存是否其新记录或现有记录。

:before_save is called everytime a record is inserted/updated in the database. So it is called on every save whether its a new record or existing record.

:before_update 被称为只有当记录更新和放大器;从来没有上新的记录。

:before_update is called only when the record is updated & never on new record.

这篇关于和before_save:before_update活动记录回调之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆