Invalid PathExpression. Must be a SingleValuedAssociationField

stax picture stax · Sep 15, 2015 · Viewed 15.6k times · Source

I'm trying to do:

class PrixRepository extends EntityRepository
{
    public function findPrixLike($film)
    {
        $query = $this->createQueryBuilder('p')
                      ->addSelect('s')
                      ->from('MG\UserBundle\Entity\SocieteDiffuseur', 's')
                      ->join('s.paysDiffs', 'pays')
                      ->where(':filmId MEMBER OF p.films')
                      ->andWhere('pays.id MEMBER OF p.pays')
                      ->setParameter('filmId', $film)
                      ->getQuery();

        $result = $query->getResult();

        return $result;
    }
}

And I get this error:

[Semantical Error] line 0, col 156 near 'id MEMBER OF': Error: Invalid PathExpression. Must be a SingleValuedAssociationField.

You can find my entity's structure here: Notice: Undefined index: joinColumns doctrine 2 + symfony 2 I tried multiple queries, but I really don't know what I have to do.

Answer

stax picture stax · Sep 15, 2015

Congratz to @olaurendeau. Like he said doctrine is expected an entity and not an id so the correct query is : (pays MEMBER OF and not pays.id...)

public function findPrixLike($film)
{
    $query = $this->createQueryBuilder('p')
              ->addSelect('s')
              ->from('MG\UserBundle\Entity\SocieteDiffuseur', 's')
              ->join('s.paysDiffs', 'pays')
              ->where(':filmId MEMBER OF p.films')
              ->andWhere('pays MEMBER OF p.pays')
              ->setParameter('filmId', $film)
              ->getQuery();

$result = $query->getResult();

return $result;