12月22日 update_columns,完成第9节。

Update_columns(attributes) //等同于update_column

直接更新database. 使用UPdate SQL 语法。

⚠️ :忽略了validations, Callbacks. 所以速度最快。但不能更新只读属性,或called on new objects.

user.update_columns(last_request_at: Time.current)

完成第九节,邮件的发生,使用了gem 'letter_opener', :group => :development.

关键词:

deliver!这个是发送邮件。

clean! :这个自定义在cart.rb中的method.用的是destroy_all,目的是清除current_cart内的cart_items.

在console中,需要用clear来清空cart.has_many 关联里面有4.3.1.8 collection.clear的解释。

移除所以关联对象,并且根据 dependent的 option。如果没有option,则使用默认的delete_all. 

原文地址:https://www.cnblogs.com/chentianwei/p/8084794.html