Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid PathExpression. Must be a SingleValuedAssociationField

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.

like image 226
stax Avatar asked Sep 15 '15 12:09

stax


1 Answers

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;
like image 160
stax Avatar answered Oct 20 '22 15:10

stax