2012-08-29 84 views
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. 

不是非常有帮助?

+0

你能提供有关抛出的异常的详细信息(邮件等)? –

+0

编辑完整的错误消息的问题。 –

回答

2

我结束了在我的自定义库法的全套子实体明确查询...

我改变了询问了:

->select('stats') 
    ->leftJoin('stats.journey', 'j') 
    ->leftJoin('j.firstStation', 'fs') 
    ->leftJoin('j.lastStation', 'ls') 

到:

->select('stats, j, fs, ls') 
    ->leftJoin('stats.journey', 'j') 
    ->leftJoin('j.firstStation', 'fs') 
    ->leftJoin('j.lastStation', 'ls') 

我猜主义的使用代理对象是不是所有的透明......