Skip to content

Instantly share code, notes, and snippets.

@dionisos2
Last active December 15, 2015 08:39
Show Gist options
  • Save dionisos2/5232623 to your computer and use it in GitHub Desktop.
Save dionisos2/5232623 to your computer and use it in GitHub Desktop.
Problem to build a SQL query with the queryBuilder
<?php
class A
{
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="B", mappedBy="")
* @Assert\Valid(traverse=true)
*/
private $Bs;
...
}
<?php
...
$queryBuilder = $this->createQueryBuilder('A')
->leftJoin('A.B', 'B')
->andWhere('B.v = plop')
->addSelect('B') //If i remove this line, i have a error show below
->leftJoin('B.C', 'C')
->andWhere('C.v = plop')
->addSelect('C');
/*
If i remove "->addSelect('B')" i get this error:
The parent object of entity result with alias 'C' was not found. The parent alias is 'B'.
*/
<?php
class B
{
/**
* @var A
*
* @ORM\ManyToOne(targetEntity="A", inversedBy="Bs")
*/
private $ownerA;
/**
* @var C
*
* @ORM\OneToMany(targetEntity="C")
*/
private $Bs;
/**
* @var string
*
* @ORM\Column(name="v", type="string", length=255)
*/
private $v;
...
}
class C
{
/**
* @var string
*
* @ORM\Column(name="v", type="string", length=255)
*/
private $v;
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment