Last active
December 15, 2015 08:39
-
-
Save dionisos2/5232623 to your computer and use it in GitHub Desktop.
Problem to build a SQL query with the queryBuilder
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
<?php | |
class A | |
{ | |
/** | |
* @var ArrayCollection | |
* | |
* @ORM\OneToMany(targetEntity="B", mappedBy="") | |
* @Assert\Valid(traverse=true) | |
*/ | |
private $Bs; | |
... | |
} |
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
<?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'. | |
*/ |
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
<?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; | |
... | |
} |
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 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