Answer the question
In order to leave comments, you need to log in
How to write a QueryBuilder query correctly?
Greetings! I have never worked with Doctrine before, so I am asking for help!
There is an entity House . It has many one-to-many related entities -
$this->getEntityManager()->createQueryBuilder()
->select('h')
->from(House::class, 'h')
->leftJoin(HouseHistoryRecord::class, 'sh', Join::LEFT_JOIN, 'sh.house = h.id')->addSelect('sh as statusHistory')
->leftJoin(HousePriceHistory::class, 'ph', Join::WITH, 'ph.house = h.id')->addSelect('ph as priceHistory')
->leftJoin(HouseEvaluation::class, 'eval', Join::WITH, 'eval.house = h.id')->addSelect('asmt as houseEvaluations')
->leftJoin(HouseInspection::class, 'insp', Join::WITH, 'insp.house = h.id')->addSelect('insp as houseInspections')
->leftJoin(HouseComments::class, 'cmts', Join::WITH, 'cmts.house = h.id')->addSelect('cmts as houseComments')
->where('h.id = :houseId')
->setParameter('houseId', $house->getId());
HouseComments$sh = $this->getEntityManager()->createQueryBuilder()
->select('sh')
->from(HouseHistoryRecord::class, 'sh')
->where('sh.house = :houseId')
->setParameter('houseId', $house->getId());
$ph = $this->getEntityManager()->createQueryBuilder()
->select('ph')
->from(HousePriceHistory::class, 'ph')
->where('ph.house = :houseId')
->setParameter('houseId', $house->getId());
$eval = $this->getEntityManager()->createQueryBuilder()
->select('eval')
->from(HouseEvaluation::class, 'eval')
->where('eval.house = :houseId')
->setParameter('houseId', $house->getId());
$insp = $this->getEntityManager()->createQueryBuilder()
->select('insp')
->from(HouseInspection::class, 'insp')
->where('insp.house = :houseId')
->setParameter('houseId', $house->getId());
$cmts = $this->getEntityManager()->createQueryBuilder()
->select('cmts')
->from(HouseComments::class, 'cmts')
->where('cmts.house = :houseID')
->setParameter('houseId', $house->getId());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question