如何在活动记录中删除? [英] How do you delete in active record?

查看:143
本文介绍了如何在活动记录中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在活动记录中删除?

我看着活动记录查询,它不会对删除,我可以看到任何东西。

  1. 删除按id,

  2. 删除像现在的对象: user.remove

  3. 可以删除基于where子句?

解决方案

这是破坏 destroy_all 方法,如

  user.destroy
User.find(15).destroy
User.destroy(15)
User.where(年龄:20).destroy_all
User.destroy_all(年龄:20)
 

另外,您可以使用删除 DELETE_ALL 将不执行:before_destroy :after_destroy 回调或任何相关的关联选项

How do you delete in active record?

I looked at Active Record Querying and it does not have anything on deleting that I can see.

  1. Delete by id,

  2. Delete the current object like: user.remove,

  3. Can you delete based on a where clause?

解决方案

It's destroy and destroy_all methods, like

user.destroy
User.find(15).destroy
User.destroy(15)
User.where(age: 20).destroy_all
User.destroy_all(age: 20)

Alternatively you can use delete and delete_all which won't enforce :before_destroy and :after_destroy callbacks or any dependent association options.

这篇关于如何在活动记录中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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