我正在使用Symfony 3.2。 我有一个名为 我想查询所有 我也尝试使用queryBuilder 比如这个答案。 p>
会引发以下错误: p>
Site code>的实体,它包含一个名为
Indication code>的另一个实体的OneToMany关系。
p>
类Site
{
/ **
* @ORM \ OneToMany(targetEntity =”IhkBundle \ Entity \ Indication“,mappedBy =”site“)
* /
private $ indication ;
}
class指示
{
/ **
* @ORM \ ManyToOne(targetEntity =“IhkBundle \ Entity \ Site”,inversedBy =“indication”)
* @ORM \ JoinColumn(name =“site_id”,referencedColumnName =“id”)
* /
private $ site;
}
code> pre>
站点 code>,其中
Indications code>可用。 我只得到一个我不知道该怎么做的ArrayCollection。 p>
$ sites = $ repository-> findAll( );
foreach($ sites as $ site){
$ site-> getIndications();
}
code> pre>
$ query = $ repository-> createQueryBuilder('s');
$ result = $ query-> where('s.indications IS NOT NULL')
- > getQuery()
- > getResult();
code> pre>
[Semantical Error]第0行,col 46附近'指示IS':错误:无效的PathExpression。 期望StateFieldPathExpression或SingleValuedAssociationField。
code> pre>
div>
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.