Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine DQL: condition on left join

I have a one to many schema: Desk has many Bills. Is it possible to fetch all Desk records with some Bill records.

I am trying to do this:

//DeskTable.class.php

public function getDesks()
{
    $q = $this->createQuery('d')
      ->leftJoin('d.Bills b')
      ->where('b.is_open = ?', true);

    return $q->execute();
}

But I get a list of Desks that have open Bills, whereas I need all Desks. Is this possible?

I am totally not a sql kind of kid, so please bear with me.

like image 679
Dziamid Avatar asked Dec 28 '22 16:12

Dziamid


1 Answers

Use Doctrine's WITH keyword (docs here):

$q = $this->createQuery('d')
  ->leftJoin('d.Bills b WITH b.is_open = ?', true)

return $q->execute();
like image 61
richsage Avatar answered Jan 08 '23 16:01

richsage