【发布时间】:2012-08-29 14:26:16
【问题描述】:
我有一个Stats 实体,它通过ManyToOne 关联与Journey 实体相关。
id:
index:
type: integer
fields:
idJourney:
type: string
// data fields...
manyToOne:
journey:
targetEntity: Journey
joinColumn:
name: idJourney
referencedColumnName: idJourney
Journey 通过两个ManyToOne 关联与Station 实体相关联:一个用于Journey 的第一个Station,一个用于最后一个。
id:
idjourney:
type: string
fields:
idFirstStation:
type: string
idLastStation:
type: string
// other info fields
manyToOne:
firstStation:
targetEntity: Station
joinColumn:
name: idFirstStation
referencedColumnName: idStation
lastStation:
targetEntity: Station
joinColumn:
name: idLastStation
referencedColumnName: idStation
最后,Station 实体:
id:
idStation:
type: string
fields:
name:
type: string
// other station info
我通过一个工作正常的自定义 Repository 方法检索 Stats 对象的集合以及所有相关的子对象。
$statCollection = $statsRepository->getStatsByDateAndArea($date, $area);
//This retrieves the expected data
$statCollection[0]->getJourney()->getFirstStation()->getName();
但是,使用 foreach 循环遍历集合不起作用:
foreach($statCollection as $stat) {
$journey = $stat->getJourney(); // works fine
$firstStationId = $journey->getFirstStationId(); // works too
$firstStation = $journey->getFirstStation(); // still works, but returns a Proxies\AcmeAppPathWhateverBundleEntityStationProxy object instead of a AcmeAppPathWhateverBundleEntityStation, but this should be transparent (as per Doctrine documentation)
$firstStationName = $firstStation->getName(); // throws an EntityNotFoundException
}
知道发生了什么吗?我应该强制 Doctrine 获取所有子实体吗?
编辑 错误信息相当简洁:
EntityNotFoundException: Entity was not found.
不是很有帮助...
【问题讨论】:
-
您能否提供更多有关抛出异常(消息等)的详细信息?
-
带有完整错误消息的已编辑问题。