我对 Doctrine queryBuilder 有问题。我有两个实体:捐赠和捐赠者。我只想做一个左连接(因为 Donations.donorId 指的是 Donateurs.id,例如。)
关于 DonationsRepository 的查询:
public function showAll()
{
$qb = $this->createQueryBuilder('dr')
->select('dr, dn')
->leftJoin('dr.donateurs','dn')
->getQuery()
->execute();
return $qb;
}
调用我的 Controller.php :
public function don(DonationsRepository $repo, Request $request)
{
$qb = $repo->showAll();
var_dump($qb);
// Then return to Twig
}
这是一个var_dump示例:
array (size=14)
0 =>
object(App\Entity\Donations)[989]
private 'id' => int 197
private 'movement' => string 'D' (length=1)
private 'departDate' =>
object(DateTime)[885]
public 'date' => string '2023-11-18 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
private 'certifDate' =>
object(DateTime)[993]
public 'date' => string '2023-11-18 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
private 'certifRef' => string 'EO62' (length=4)
private 'productName' => string 'Clémentines' (length=12)
private 'donorId' => int 1
private 'family' => string 'Frais' (length=5)
private 'recipient' => string 'EO62' (length=4)
private 'carrierId' => int 3
private 'nbPallet' => int 33
private 'weight' => int 19720
private 'billDate' =>
object(DateTime)[891]
public 'date' => string '2023-11-18 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
private 'billReceptionDate' =>
object(DateTime)[992]
所有数据仅来自我的捐赠实体......但是如果我execute()从我的存储库中删除它,并且我$qb->execute从我的控制器中执行一个......var_dump返回给我类似的东西(这是一个示例,转储太大)