アソシエーションを通じてエンティティに関連付けられStats
ているエンティティがあります。Journey
ManyToOne
id:
index:
type: integer
fields:
idJourney:
type: string
// data fields...
manyToOne:
journey:
targetEntity: Journey
joinColumn:
name: idJourney
referencedColumnName: idJourney
はJourney
、Station
2つの関連付けを通じてエンティティにManyToOne
関連付けられています。1つは最初Station
のJourney
、もう1つは最後の関連付けです。
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.
あまり役に立たなかった...