1

アソシエーションを通じてエンティティに関連付けられStatsているエンティティがあります。JourneyManyToOne

id:
    index:
        type: integer

fields:
        idJourney:
        type: string
// data fields...
manyToOne:
    journey:
        targetEntity: Journey
        joinColumn:
            name: idJourney
            referencedColumnName: idJourney

JourneyStation2つの関連付けを通じてエンティティにManyToOne関連付けられています。1つは最初StationJourney、もう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.

あまり役に立たなかった...

4

1 に答える 1

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')

Doctrineによるプロキシオブジェクトの使用はそれほど透過的ではないと思います...

于 2012-08-30T09:47:23.073 に答える