Reputation: 105
EDIT: example
{% if Docs.DocsList is empty %}
return false
or
{% if Docs.DocsList.isEmpty %}
return false or
{% if Docs.DocsList.first is defined %}
get error.
first two get all DocsList elements from db witch i don't need.
Upvotes: 0
Views: 1187
Reputation: 3051
Make a service.
Something like
$docListChecker->isEmpty($docs);
End then make a query that will fetch only count of entities, but not entities themselves.
$result = $qb->select('COUNT(l)')
->from('YourBundle:docsList' , 'l')
->leftJoin('l.docs.','d')
->where('d.id = :id')
->setParameter('id', $id)
->getQuery()
->getSingleScalarResult();
This service you can pass to twig and check your list as
{% if checker.isEmpty(Docs.DocsList) %}
Or even you can make a twig filter and use it like
{% if Docs.DocsList | isListEmpty %}
Upvotes: 1