Tigran
Tigran

Reputation: 653

Symfony DQL syntax error

I'm trying to do DQL query, but having some troubles with it...

$user = $this->getUser();

$query = $em->createQuery(
    'SELECT p
       FROM AppBundle:User u
         JOIN AppBundle:Follower f
         JOIN AppBundle:Photo p 
           WHERE u.id = :id
           AND f.follower_id = :id
           AND p.user_id = f.user_id'
)->setParameter('id', $user->getId());

I am trying to get Photos (AppBundle:Photo) of those users, to whom the logged user is following.

Getting next error:

`[Syntax Error] line 0, col 128: Error: Expected =, <, <=, <>, >, >=, !=, got 'p'`

Whats wrong here with 'p' ?

Upvotes: 0

Views: 152

Answers (2)

BENARD Patrick
BENARD Patrick

Reputation: 30975

I don't understand why follower are in your code, I don't see relation with photo...

After, I think you call Join but I don't see the relation you made with the photo...

$query = $em->createQuery(
'SELECT p
  FROM AppBundle:Photo p       
     JOIN p.user u
       WHERE u.id = :id ')->setParameter('id', $user->getId());

Here is a part of the official doc : Example:

Regular join of the address:

createQuery("SELECT u FROM User u JOIN u.address a WHERE a.city = 'Berlin'"); $users = $query->getResult();

Fetch join of the address:

createQuery("SELECT u, a FROM User u JOIN u.address a WHERE a.city = 'Berlin'"); $users = $query->getResult();

Upvotes: 1

Zorbaxis Bts Sio Slam
Zorbaxis Bts Sio Slam

Reputation: 41

did yu try this?:

$query = $em->createQuery(
'SELECT p
  FROM AppBundle:Photo p       
     JOIN AppBundle:Follower f
     JOIN  AppBundle:User u
       WHERE u.id = :id
       AND f.follower_id = :id
       AND p.user_id = f.user_id' )->setParameter('id', $user->getId());

Upvotes: 0

Related Questions