开发者

Deleting a record from database

In Ruby on Rai开发者_如何学运维ls, is it @variable.delete or @variable.destroy


@variable.destroy will call all callbacks (before_destroy etc.) as well as ensure associations are respected. @variable.delete just calls the raw database query to delete the object. You're generally much safer off using destroy even if it's more expensive.


Assuming that you're using ActiveRecord, and that @variable is an instance of an ActiveRecord::Base subclass, you call @variable.destroy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜