How to JOIN without a relationship in Doctrine?

后端 未结 1 356
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 12:24

I have an entity Log (table log) with members resourceType and resourceId (with columns resource_log and

1条回答
  •  攒了一身酷
    2021-01-13 12:57

    The JOIN without relationship can be implemented like this:

    $queryBuilder = $this->entityManager->createQueryBuilder();
    $queryBuilder->select('l')->from(Log::class, 'l');
    $queryBuilder->join(
        Order::class,
        'o',
        \Doctrine\ORM\Query\Expr\Join::WITH,
        'o.id = l.resourceId'
    );
    ...
    $queryBuilder
        ->where('o.myOrderProperty = :myOrderProperty')
        ->setParameter('myOrderProperty', $myOrderProperty);
    

    The only problem is, that the joined entities are not added to the main entity, so that $myLog->getOrder(...) returns null.

    0 讨论(0)
提交回复
热议问题