结果arrray中的Symfony2内部联接返回代理



我知道这个查询工作很有魅力:

$result = $this->getEntityManager()->createQueryBuilder()
    ->select('banner','customer')
    ->from("MyBundle:Banner", 'banner')
    ->innerJoin('banner.customer', 'customer')
    ->getQuery()
    ->getResult();

稍后,在视图中,我可以迭代并打印{{banner.name}}{{banner.customer.name}},而无需对数据库进行额外查询。

但是,innerJoin:上有一点变化的相同查询

$result = $this->getEntityManager()->createQueryBuilder()
    ->select('banner','customer')
    ->from("MyBundle:Banner", 'banner')
    ->innerJoin('MyBundle:Customer', 'customer', 'WITH', 'customer.id = banner.customer')
    ->getQuery()
    ->getResult();
foreach ($result as $e)
    echo get_class($e).'<br/>';
die(1);

此打印:

MyBundleEntityBanner
Proxies__CG__MyBundleEntityCustomer
MyBundleEntityBanner
MyBundleEntityBanner
Proxies__CG__MyBundleEntityCustomer
MyBundleEntityBanner
MyBundleEntityBanner
Proxies__CG__MyBundleEntityCustomer
MyBundleEntityBanner

所以,如果我迭代这个结果,期望一个MyBundleEntityBanner对象,我会遇到麻烦,所以:

这是像第二个例子一样进行innerJoin的预期结果吗
是否需要额外的function callsyntaxdoctrine/symfony setup才能使其像第一个示例一样工作?

感谢

使用双向oneToMany并从innerJoin调用中删除WITH

Customer:
  type: entity
  oneToMany:
    banners:
      targetEntity: Banner
      mappedBy: customer
Banner:
  type: entity
  manyToOne:
    customer:
      targetEntity: Customer
      inversedBy: banners
      joinColumn:
        name: customer_id
        referencedColumnName: id

相关内容

  • 没有找到相关文章

最新更新