D
D
Dmitry Baskakov2021-07-02 06:51:01
PHP
Dmitry Baskakov, 2021-07-02 06:51:01

How to do an UPDATE JOIN query in Doctrine?

There is a code:

$em = $this->getServiceLocator()->get(EntityManager::class);
$qb = $em->createQueryBuilder();
$qb->update(ReCall::class, 'rc')
    ->innerJoin(CallChannel::class, 'ch', Join::WITH, 'rc.call = ch.call')
    ->set('rc.reached', '1')
    ->where('rc.reached = 0 AND ch.shoulder = \'A\' AND ch.callerPhone = :phone')
    ->setParameter('phone', $channel->getCallerPhone());
$qb->getQuery()->getResult();


There is an error:
[Semantical Error] line 0, col 79 near 'ch.shoulder =': Error: 'ch' is not defined.Call not found


A similar design that works
$em = $this->getServiceLocator()->get(EntityManager::class);
$qb = $em->createQueryBuilder();
$qb->select('rc')
    ->from(ReCall::class, 'rc')
    ->where('rc.reached = 0 AND ch.shoulder = \'A\' AND ch.callerPhone = :phone')
    ->setParameter('phone', $callerPhone)
    ->innerJoin(CallChannel::class, 'ch', Join::WITH, 'rc.call = ch.call')
    ->orderBy('rc.createdDatetime');
$data = $qb->getQuery()->getResult();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2021-07-02
@index0h

Use raw sql and don't worry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question