Invalid PathExpression. Must be a SingleValuedAssociationField
Asked Answered
N

1

7

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.

Neotropical answered 15/9, 2015 at 12:11 Comment(2)
Have you tried removing the ".id" part of "pays.id". I think doctrine is expected an entity and not an id.Predestination
I just tried and it works fine. Thank u @Predestination , u saved my day !Neotropical
N
20

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;
Neotropical answered 15/9, 2015 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.