Skip to content

Instantly share code, notes, and snippets.

@guilhermeblanco
Created June 5, 2017 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermeblanco/1b736414a56aa261591f5b62b07b60dc to your computer and use it in GitHub Desktop.
Save guilhermeblanco/1b736414a56aa261591f5b62b07b60dc to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Client
{
/**
* @ORM\Column(type="bigint")
* @ORM\Id @ORM\AutoGenerated
*/
public $id;
/** ... */
public $clientStore;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class ClientStore
{
/**
* @ORM\Column(type="bigint")
* @ORM\Id @ORM\AutoGenerated
*/
public $id;
/** ... */
public $location;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Location
{
/**
* @ORM\Column(type="bigint")
* @ORM\Id @ORM\AutoGenerated
*/
public $id;
}
<?php
$qb = $entityManager->createQueryBuilder();
$qb
->select(['c', 'cs', 'l'])
->from('AppBundle\Entity\Client', 'c')
->innerJoin('c.clientStore', 'cs')
->innerJoin('cs.location', 'l')
->where('l.id = :location_id')
->addParameter('location_id', 123)
$result = $qb->getQuery()->getResult();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment