我有一个通过关联与实体Stats
相关的实体。Journey
ManyToOne
id:
index:
type: integer
fields:
idJourney:
type: string
// data fields...
manyToOne:
journey:
targetEntity: Journey
joinColumn:
name: idJourney
referencedColumnName: idJourney
与实体通过两个关联关联:一个与 中的第一个关联Journey
,一个与最后一个关联。Station
ManyToOne
Station
Journey
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
我通过一个工作正常的自定义存储库方法检索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.
不是很有帮助...