« Programmation PHP avec Symfony/Doctrine » : différence entre les versions

Contenu supprimé Contenu ajouté
Ligne 361 :
<syntaxhighlight lang=php>
return $this->createQueryBuilder('u')
->innerJoin('u.company', 'c', 'u.company = c.id')
->addSelect('c')
->where('u.isActive = true')
->andWhere('c.isClosed = false')
->orderBy('u.lastName', 'ASC')
->addOrderBy('c.namefirstName', 'ASC')
;
</syntaxhighlight>
 
On peut même préciser les champs à sélectionner et la clé de jointure :
<syntaxhighlight lang=php>
return $this->createQueryBuilder('u')
->select(['u.lastName as name', 'u.company'])
->innerJoin('u.company', 'c', 'u.company = c.id')
->addSelect(['c.id', 'c.name'])
->where('u.isActive = true')
->andWhere('c.isClosed = false')
->orderBy('u.lastName', 'ASC')
->addOrderBy('c.firstName', 'ASC')
;
</syntaxhighlight>