为什么软删除的实体出现在查询结果中? [英] Why soft deleted entities appear in query results?

查看:245
本文介绍了为什么软删除的实体出现在查询结果中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的对象:

  class Post Enloquent {

/ **
*模型使用的数据库表。
*
* @var string
* /
protected $ table ='posts';
protected $ softDelete = true;

...

软删除开启。



现在,如果我删除了一个帖子,它会得到一个'deleted_at'时间戳记:





问题是,当我搜索或只使用 all()显示帖子,软删除的项目出现在那里。什么是错误?

解决方案

使用Eloquent时,软删除功能可以正常工作。如果您使用查询构建器查询结果,则最终会看到所有记录已经被丢弃,而不是被丢弃。



目前尚不清楚Laravel 4的文档,但是看到软删除的概念只是出现在雄辩的ORM - 软删除,而不是在查询生成器下,我们只能假设:软删除仅适用于雄辩的ORM


I am trying to implement soft deleting concept.

Here is my object:

class Post extends Eloquent {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'posts';
    protected $softDelete = true;

    ...

Soft delete is on.

Now, if I 'delete' a post, it gets a 'deleted_at' timestamp:

The problem is, when I search or just use all() to display the posts, the soft deleted items appears there. What is wrong?

解决方案

The soft deleting feature works when using Eloquent. If you are querying the results with query builder you will eventually see all the records trashed and not trashed.

It is not clear in the current docs of Laravel 4, but seeing that the concept of soft deleting just appears under Eloquent ORM - Soft Deleting and not under Query Builder, we can only assume that: soft delete only works with Eloquent ORM.

这篇关于为什么软删除的实体出现在查询结果中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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