简体   繁体   English

有什么区别:before_save和:before_update Active Record回调?

[英]What is the difference between the :before_save and :before_update Active Record callbacks?

Could someone please explain to me the difference between the :before_save and :before_update Active Record callbacks in Ruby on Rails 4? 有人可以向我解释:before_update Ruby on Rails 4中的:before_save:before_update Active Record回调之间的区别吗?

I read through the official documentation on Active Record callbacks, but I couldn't find a granular-enough explanation. 我阅读了有关Active Record回调的官方文档,但我找不到足够精细的解释。

:before_save is called everytime a record is inserted/updated in the database. :before_save每次在数据库中插入/更新记录时都会调用:before_save So it is called on every save whether its a new record or existing record. 因此,无论是新记录还是现有记录,都会在每次保存时调用它。

:before_update is called only when the record is updated & never on new record. :before_update仅在更新记录:before_update调用:before_update并且永远不会在新记录上调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM