【发布时间】:2015-07-01 15:39:18
【问题描述】:
这个问题一直困扰着我。 我正在尝试在 symfony 中使用 DQL 加入几个表,但它不断抛出异常:
“对象“AppBundle\Entity\Keyword”的方法“排名”在第 37 行的@App/default/index.html.twig 中不存在”
这是我的 DQL:
$query = $em->createQuery(
'SELECT e,k,r
FROM AppBundle:Keyword k
JOIN k.company c
LEFT JOIN k.entry e
LEFT JOIN e.rankings r
WHERE c.user = :id
ORDER BY k.name ASC'
)->setParameter('id',$user_id);
$keywords = $query->getResult();
我想我知道问题所在 - 但我不知道如何解决它。 我的关键字实体如下所示:
AppBundle\Entity\Keyword:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
manyToOne:
company:
targetEntity: AppBundle\Entity\Company
oneToMany:
entry:
targetEntity: AppBundle\Entity\Entry
mappedBy: keyword
lifecycleCallbacks: { }
请注意,排名实体和关键字实体之间没有直接连接关系 - 该关系在条目实体中,即关键字实体和排名实体之间的链接:
AppBundle\Entity\Entry:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
path:
type: string
length: 255
manyToOne:
keyword:
targetEntity: AppBundle\Entity\Keyword
oneToMany:
rankings:
targetEntity: AppBundle\Entity\Ranking
mappedBy: entry
lifecycleCallbacks: { }
这是排名实体:
AppBundle\Entity\Ranking:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
position:
type: integer
visits:
type: integer
nullable: TRUE
bounces:
type: integer
nullable: TRUE
date:
type: datetime
manyToOne:
entry:
targetEntity: AppBundle\Entity\Entry
lifecycleCallbacks: { }
感谢各种帮助! :)
编辑
好的,如果我将上面编写的 DQL 传递给 twig 模板: 如果它是 manyToOne 关系,我如何检索排名? 如果我这样做:
{% for ranking in keyword.entry.rankings %}
<td>{{ ranking.id }}</td>
{% endfor %}
它给了我对象“Doctrine\ORM\PersistentCollection”的方法“排名”在第 37 行的 @App/default/index.html.twig 中不存在
【问题讨论】:
标签: php entity-framework symfony doctrine-orm