【问题标题】:how to select entity with contition one to many entity more than zero如何选择具有多于零的一对多实体的实体
【发布时间】:2017-03-02 15:28:15
【问题描述】:

我得到了实体任务,一个任务得到了用 oneToMany 收集实体, 我想选择少于任务中设置的 maxParticipant 的任务,我尝试了一些但指望 oneToMany 关系不存在

public function getMissionGroupByCities()
{
    $qb = $this->createQueryBuilder('m')
        ->select('COUNT(m) as count_project, m_city.id as id, IDENTITY(m_city.nameLibelle) as libelle, m_city.latitude, m_city.longitude')
        ->leftJoin('m.project', 'm_project')
        ->leftJoin('m.city', 'm_city')
        ->groupBy('m.city')
        ->where('m_project.state IN (2,3,4)')
        ->andWhere('CURRENT_TIMESTAMP() < m_project.dateEnd')
        ->andWhere('CURRENT_TIMESTAMP() < m.dateBegin')
        ->andWhere('count(m.collects) < m.maxParticipant');

    return $qb->getQuery()->getResult();
}

[语义错误] line 0, col 346 near 'collects)

我怎样才能做最后的测试? :andWhere('count(m.collects)

【问题讨论】:

    标签: symfony doctrine-orm


    【解决方案1】:

    尝试使用有从句:

        ->having('count(m.collects) < m.maxParticipant');
    

    希望有帮助

    【讨论】:

    • 否,col 365 靠近 'collects)
    • count(m.collects.id)?
    猜你喜欢
    • 2011-08-25
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 2016-01-13
    相关资源
    最近更新 更多