Created
March 19, 2018 22:52
-
-
Save uelnur/630bdf018a0623429acbc6b5febe9492 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @ORM\Table(name="users") | |
* @ORM\Entity(repositoryClass="UserRepository") | |
*/ | |
class User | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="IDENTITY") | |
* @ORM\Column(type="integer") | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column() | |
*/ | |
protected $name; | |
/** | |
* @ORM\OneToMany(targetEntity="Address", mappedBy="user") | |
*/ | |
protected $addresses; | |
} | |
/** | |
* @ORM\Table(name="users_address") | |
* @ORM\Entity() | |
*/ | |
class Address | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="IDENTITY") | |
* @ORM\Column(type="integer") | |
*/ | |
protected $id; | |
/** | |
* @ORM\ManyToOne(targetEntity="User", inversedBy="addresses") | |
* @ORM\JoinColumn(name="user_id", referencedColumnName="id") | |
*/ | |
protected $user; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserRepository extends ServiceEntityRepository | |
{ | |
public function getUsersWithAddresses() | |
{ | |
return $this->createQueryBuilder('u') | |
->select(['u', 'a']) | |
->join('u.addresses', 'a') | |
->getQuery() | |
->getResult() | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment