I have read a bunch of questions here on SO about this error but still cannot get rd of it. I have 3 entities - Site, User and Tags. One site can have one unique user, but different users may have same tags and vice versa. One tag in its table has a FK to a user and to a site. I am trying to display all tags that are related to one particular site with the following code:
->add('tags','entity', array(
'class'=> 'MyBundle:Tags',
'query_builder' => function(EntityRepository $er) use ($siteid)
{
return $er->createQueryBuilder('s')->where('s.asiteid = :siteid')
->setParameter('siteid', $siteid);
}
Also I tried this:
'query_builder' => function(EntityRepository $er) use ($siteid) {return $er->createQueryBuilder('t')
->join('\MyBundle\Entity\Mysites','ta', \Doctrine\ORM\Query\Expr\Join::WITH,'t.asiteid=ta.id')
->where('t.asiteid = :asiteid')
->setParameter('asiteid', $siteid);}
Property mapping in Tags entity is as follows:
manyToMany:
userid:
targetEntity: MyBundle\Entity\User
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
userid:
referencedColumnName: id
orphanRemoval: false
asiteid:
targetEntity: \MyBundle\Entity\Mysites
cascade: { }
mappedBy: asiteid
inversedBy: id
joinColumns:
siteid:
referencedColumnName: id
orphanRemoval: false
But in any case I get [Semantical Error] line 0, col 113 near 'asiteid=ta.id': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected. Any ideas would be welcome.
The issue was solved by changing from ManyToMany to ManyToOne. I regenerated entities from existing DB and everything worked fine.