Ich benutze Symfony 3.2. Ich habe eine Entität mit dem Namen Site
, die eine OneToMany-Beziehung zu einer anderen Entität namens Indication
enthält. Abfrage für nicht null OneToMany Beziehung in Symfony/Lehre
class Site
{
/**
* @ORM\OneToMany(targetEntity="IhkBundle\Entity\Indication", mappedBy="site")
*/
private $indications;
}
class Indication
{
/**
* @ORM\ManyToOne(targetEntity="IhkBundle\Entity\Site", inversedBy="indications")
* @ORM\JoinColumn(name="site_id", referencedColumnName="id")
*/
private $site;
}
Ich möchte für alle sites
abfragen, wo Indications
verfügbar sind. Ich bekomme nur eine ArrayCollection, mit der ich nicht weiß, was ich damit anfangen soll.
$sites = $repository->findAll();
foreach ($sites as $site) {
$site->getIndications();
}
Ich habe auch versucht, in this answer die Querybuilder wie zu verwenden.
$query = $repository->createQueryBuilder('s');
$result = $query->where('s.indications IS NOT NULL')
->getQuery()
->getResult();
, die die folgenden Fehler führen:
[Semantical Error] line 0, col 46 near 'indications IS': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.