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

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

问题描述

我正在尝试实现软删除概念.

I am trying to implement soft deleting concept.

这是我的对象:

class Post extends Eloquent {

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

    ...

软删除已开启.

现在,如果我删除"一个帖子,它会获得一个deleted_at"时间戳:

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

问题是,当我搜索或仅使用 all() 显示帖子时,软删除的项目会出现在那里.怎么了?

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

推荐答案

软删除功能在使用 Eloquent 时有效.如果您使用 query builder 查询结果,您最终会看到所有记录都被丢弃而不是被丢弃.

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.

目前 Laravel 4 的文档中并不清楚,但是看到 软删除 的概念只是出现在 Eloquent ORM - 软删除 而不是在 Query Builder 下,我们只能假设:软删除仅适用于 Eloquent ORM.

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天全站免登陆