My raw sql:
SELECT cc.id, cc.name, cc.status, cc.updated, ap.profile_id, pp.name
FROM `cars__cars` as cc
INNER JOIN `cars__profiles` AS cp on cp.car_id = cc.id
inner join `cars__brands` as cb on cb.car_id=cc.id
inner join `profiles__profiles` as pp on pp.id = cp.profile_id
where cp.profile_id in (5991, 1, 2)
and
cb.brand_id=1
ORDER by cc.updated DESC
LIMIT 1;
it's working fine, now when i convert this into query builder inside symfony
$qb = $this->createQueryBuilder('cars');
$qb
->select('cars, ap.id, p.name')
->innerJoin('cars.brands', 'cb')
->innerJoin('cars.profiles', 'cp')
->innerJoin('profile', 'p')
->where($qb->expr()->eq('cars.status', ':status'))
->andWhere($qb->expr()->eq('cb.id', ':brandId'))
->andWhere($qb->expr()->in('cp.id', ':profilesIds'))
->andWhere($qb->expr()->in('cp.id', 'p.id'))
->setParameters([
'status' => CarStatus::SOLD,
'brandId' => $brandId,
'profilesIds' => $profilesIds,
])
->addOrderBy('cars.updated', 'DESC')
->setMaxResults(1);
return $qb->getQuery()->getOneOrNullResult();
ive got this error: Error: Class 'profile' is not defined. But if i remove this last innerJoin with table profile and last where condition and p.name from select, my code its working, however i need to get profile name which is stored inide profile table, any help?