My database structure looks like this:
user <-> personal <-> school
so the personal object holds information about the user and the school like this:
class Personal
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\ManyToOne(targetEntity="user", inversedBy="schools", fetch="EAGER")
*/
private $user;
/**
* @var string
*
* @ORM\ManyToOne(targetEntity="school", inversedBy="personal", fetch="EAGER")
*/
private $school;
}
So I want to fetch the schools of an user:
$query = $qb
->select('school')
->from('AppBundle:School', 'school')
->leftJoin('school.personal', 'p', 'WITH', 'p.user = :user')
->setParameters(array(':user' => $user))
->getQuery();
I also tried the following:
$query = $qb
->select('school')
->from('AppBundle:School', 'school')
->leftJoin('u.personal', 'personal')
->leftJoin('personal.user', 'pu')
->where('pu = :user')
->setParameters(array(':user' => $user))
->getQuery();
But nothing works. The first gives me back all Schools :S. The second query gives no school back! :(
How can I get all schools for user?