4

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.

Dziamid
  • 11,225
  • 12
  • 69
  • 104

1 Answers1

10

Use Doctrine's WITH keyword (docs here):

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

return $q->execute();
richsage
  • 26,912
  • 8
  • 58
  • 65