I am using Symfony v3.4 branch with Doctrine.
I am having trouble translating SQL query to Doctrine ORM query.
I have 3 tables.
- Shop
- Firm
- User
User --> 1:1 --> Firm --> 1:1 --> Shop
(Symfony developer tool bar reports that associations in tables are made correctly).
I want to get Shop data that corresponds to cretain User in one query.
My SQL, that get a result:
SELECT * FROM mp2_fos_user as u LEFT JOIN mp2_firm AS f ON u.id = f.firmUserId LEFT JOIN mp2_shop AS s ON f.id = s.shopFirmId WHERE u.id = 1 My Doctrine ORM query
$query = $em->createQueryBuilder() ->select('u, f, s') ->from('App:User', 'u') ->leftJoin('u.userFirm WITH u.id = f.firmUserId', 'f') ->leftJoin('f.firmShop WITH f.id = s.shopFirmId', 's') ->where('u.id = :user_id') ->setParameter('user_id', $user_id) ->getQuery(); at the moment running the code results in an error
[Syntax Error] line 0, col 57: Error: Expected end of string, got 'u'
What would be best practice for my issue?
Help would be much appreciated, Thank you!
UPDATE
tried:
$query = $em->createQueryBuilder() ->select('s.id') ->from('App:User', 'u') ->leftJoin('u.userFirm WITH f.firmUser = u', 'f') ->leftJoin('f.firmShop WITH s.shopFirm = f', 's') ->where('u.id = :user_id') ->setParameter('user_id', $user_id) ->getQuery(); got [Syntax Error] line 0, col 54: Error: Expected end of string, got 'f'
mp2_firmentity has a relationship with themp2_fos_userentity via the propertyfirmUser, then try the WITH statement asWITH f.firmUser = u. Same with idea withfirmShop