I am using Symfony 3.2. I have an entity called Site
which contains a OneToMany relationship to another entity called Indication
.
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;
}
I want to query for all sites
where Indications
are available. I only get an ArrayCollection which I don't know what to do with.
$sites = $repository->findAll();
foreach ($sites as $site) {
$site->getIndications();
}
I also tried to use the queryBuilder like in this answer.
$query = $repository->createQueryBuilder('s');
$result = $query->where('s.indications IS NOT NULL')
->getQuery()
->getResult();
which throws the following error:
[Semantical Error] line 0, col 46 near 'indications IS': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.