1
我有一个Stats
实体通过ManyToOne
关联与Journey
实体相关。一个用于Journey
的第一Station
,一个过去:Symfony2 - EntityNotFoundException
id:
index:
type: integer
fields:
idJourney:
type: string
// data fields...
manyToOne:
journey:
targetEntity: Journey
joinColumn:
name: idJourney
referencedColumnName: idJourney
的Journey
通过两个ManyToOne
协会相关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
我通过工作正常的自定义库方法来检索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.
不是非常有帮助?
你能提供有关抛出的异常的详细信息(邮件等)? –
编辑完整的错误消息的问题。 –