0

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' ?

2
  • p is the table alias, try to select p.*. But I think Doctrine will not allow you to select something that does not contain at least your main table, i.e. u.* Commented Nov 30, 2015 at 20:23
  • I dont need Users info. What will be the correct dql then? Commented Nov 30, 2015 at 20:27

2 Answers 2

1

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();

Sign up to request clarification or add additional context in comments.

2 Comments

The task is: Get photos of THOSE users, to whom current user is following.
So first of all i need to Join with Follower to get all followers then join Photo to get photos
0

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());

2 Comments

I did, i have almost same error - [Syntax Error] line 0, col 128: Error: Expected =, <, <=, <>, >, >=, !=, got 'u'
try this: select p,f,u from etc etc ... ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.