- 有3个实体文档,DocsPerm,DocsList
- 在条令中,我只选择Docs+DocsPerm
- 然后我检查Docs->getDocsList->isEmpty((,然后从数据库中选择所有DocsList
- 如何检查DocsList是空的还是在没有理由从数据库中选择所有元素的情况下选择的?谢谢
编辑:示例
- 有2个控制器。(一个带有Docs+perm,第二个Docs+DocList(
- 有一个用于2个控制器的树枝模板。这里我不想检查
{% if Docs.DocsList is empty %}
返回false或
{% if Docs.DocsList.isEmpty %}
返回false或
{% if Docs.DocsList.first is defined %}
获取错误。
前两个从db-wwitch获取我不需要的所有DocsList元素。
创建服务。
类似的东西
$docListChecker->isEmpty($docs);
End,然后进行一个查询,该查询将只获取实体的计数,而不获取实体本身。
$result = $qb->select('COUNT(l)')
->from('YourBundle:docsList' , 'l')
->leftJoin('l.docs.','d')
->where('d.id = :id')
->setParameter('id', $id)
->getQuery()
->getSingleScalarResult();
您可以将此服务传递到trick并作为检查您的列表
{% if checker.isEmpty(Docs.DocsList) %}
甚至你也可以制作一个树枝过滤器,像一样使用它
{% if Docs.DocsList | isListEmpty %}