简体   繁体   English

如何分开结果

[英]How do I separate the results

I have the following query on Doctrine QueryBuilder: 我在Doctrine QueryBuilder上有以下查询:

$qb = $this->createQueryBuilder('e')
            ->select('e.id, e.name, e.body, e.teaser, e.slug, e.dateBegin, e.dateEnd, e.dateTbd, v.name AS v_name')
            ->innerJoin('e.venue', 'v')
            ->where('v.name LIKE :TBD')
            ->orWhere('v.name LIKE :TBA')
            ->orWhere('e.name LIKE :TBD')
            ->orWhere('e.name LIKE :TBA')
            ->orWhere('e.name LIKE \'none\'')
            ->orWhere('e.name LIKE \'n/a\'')
            ->orWhere('e.teaser LIKE :TBD')
            ->orWhere('e.body LIKE :TBD')
            ->orWhere('e.dateTbd=true')
            ->orWhere('TIME(e.dateBegin) < :earlyMorning AND TIME(e.dateBegin) > :lateNight')
            ->setParameter('TBA', '%TBA%')
            ->setParameter('TBD', '%TBD%')
            ->setParameter('earlyMorning', '06:00:00')
            ->setParameter('lateNight', '23:00:00');

How I can separate the results by 'where' clause in this query. 如何在此查询中按“ where”子句分隔结果。 I need to display every event with criteria which listed in where clause. 我需要使用where子句中列出的条件来显示每个事件。

I can't see a way of achieving this easily, especially if we are to assume you're using this to retrieve a standard doctrine entity collection, since additional grouping / properties wouldn't really be something you could pass into these. 我看不到一种轻松实现此目的的方法,尤其是如果我们假设您正在使用它来检索标准的学说实体集合时,因为附加的分组/属性实际上并不是您可以传递给它们的东西。

If you need to group these simply to display them slightly differently as they're output, say, in your markup, I'd consider adding additional methods into your entity's class to allow you detect which 'type' they are based on similar criteria defined in your query, eg using standard string matching functions. 如果您只需要对它们进行分组以在输出时稍微不同地显示它们,例如,在您的标记中,我会考虑在实体的类中添加其他方法,以允许您基于定义的相似标准检测它们的“类型”在查询中,例如使用标准的字符串匹配功能。

Otherwise your options are going to be filtering the collection (ArrayCollections carry a method for doing that easily) or separating it out into multiple queries, which given your approach, I assume you are trying to avoid. 否则,您的选择将是过滤集合(ArrayCollections带有一种可以轻松做到这一点的方法)或将其分为多个查询,考虑到您的方法,我认为您正在尝试避免这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM