我有三个实体: HandsetSubscription、手机和订阅。
HandsetSubscription的yaml是:
App\SoBundle\Entity\HandsetSubscription:
type: entity
table: handset_subscription
manyToOne:
handset:
targetEntity: Handset
subscription:
targetEntity: Subscription
id:
id:
type: integer
generator: { strategy: AUTO }
options: { unsigned: true }
fields:
amount:
type: integer
nullable: false
options: { default: 0, unsigned: true }
discount:
type: integer
nullable: false
options: { default: 0, unsigned: true }查询:
SELECT hs,s,h
FROM \App\SoBundle\Entity\HandsetSubscription hs
JOIN \App\SoBundle\Entity\Subscription s with s.id = hs.subscription
AND s.mins = 150
AND s.mb = 250
AND s.sms = 150
JOIN \App\SoBundle\Entity\Handset h with h.id = hs.handset 这些是检索到的条目的类名:
App\SoBundle\Entity\HandsetSubscription
Proxies\__CG__\App\SoBundle\Entity\Subscription
Proxies\__CG__\App\SoBundle\Entity\Handset
App\SoBundle\Entity\HandsetSubscription
Proxies\__CG__\App\SoBundle\Entity\Handset
App\SoBundle\Entity\HandsetSubscription
Proxies\__CG__\App\SoBundle\Entity\Handset
…我希望只返回HandsetSubscription实体。为什么我也有订阅和手机的代理?
通过向手机和订阅映射添加fetch,并从查询中的SELECT语句中删除手机和订阅,我将只获得HandsetSubscription,但我希望通过fetch联接来实现这一点,如手册(http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html#joins)所述。
更新
引用上述链接:
获取地址的连接:
<?php
$query = $em->createQuery("SELECT u, a FROM User u JOIN u.address a WHERE a.city = 'Berlin'");
$users = $query->getResult();当Doctrine用fetch-join补充查询时,它返回结果数组根级FROM子句中的类。在前面的示例中,返回一个用户实例数组,并将每个用户的地址提取并补充到User#address变量中。如果您访问address,则不需要延迟加载与另一个查询的关联。
发布于 2014-12-03 14:23:58
非常感谢#主义irc渠道的veonik来解决这个问题。
与其加入实体的完全限定名称,不如加入协会。因此,查询变成:
SELECT hs,s,h
FROM \App\SoBundle\Entity\HandsetSubscription hs
JOIN hs.subscription s with s.id = hs.subscription
AND s.mins = 150
AND s.mb = 250
AND s.sms = 150
JOIN hs.handset h with h.id = hs.handset https://stackoverflow.com/questions/27175873
复制相似问题