如何编写DQL select语句以搜索单个表继承表中的部分实体,但不是全部实体 [英] How to write a DQL select statement to search some, but not all the entities in a single table inheritance table

查看:52
本文介绍了如何编写DQL select语句以搜索单个表继承表中的部分实体,但不是全部实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在一个表中有3个实体。我需要能够在一个select语句中搜索3个实体中的2个,但是我不确定如何执行此操作。

So I have 3 entities within one table. I need to be able to search 2 out of the 3 entities in one select statement, but I'm not sure how to do this.

推荐答案

在dql查询中使用 INSTANCE OF 运算符,如下所示(其中 User 是您的基类):

Use the INSTANCE OF operator in your dql query like this (where User is your base class):

$em->createQuery('
    SELECT u 
    FROM Entity\User u 
    WHERE (u INSTANCE OF Entity\Manager OR u INSTANCE OF Entity\Customer)
');

Docrine在 WHERE user.type ='中将其在sql查询中翻译...'条件。

Doctrine translates this in the sql query in a WHERE user.type = '...' condition.

请参见此处以获取有关dql查询语法的更多详细信息。

See here for more details on the dql query syntax.

这篇关于如何编写DQL select语句以搜索单个表继承表中的部分实体,但不是全部实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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