1

I have a Stats entity that is related to a Journey entity through a ManyToOne association.

id:
    index:
        type: integer

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

The Journey is related to the Station entity through two ManyToOne association: one for the first Station of the Journey, one for the last.

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

Finally, the Station entity :

id:
    idStation:
        type: string
fields:   
    name:
        type: string
// other station info

I retrieve a collection of Stats objects with all related sub-objects via a custom Repository method which works fine.

$statCollection = $statsRepository->getStatsByDateAndArea($date, $area);

//This retrieves the expected data
$statCollection[0]->getJourney()->getFirstStation()->getName();

However, iterating through the collection with a foreach loop doesn't work:

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
}

Any idea what's going on ? Should I force Doctrine to fetch all sub entities ?

EDIT The error message is fairly laconic :

EntityNotFoundException: Entity was not found.

Not very helpful...

2
  • Can you give more details about the exception thrown (message, etc...)? Commented Aug 29, 2012 at 16:34
  • Edited question with full Error message. Commented Aug 30, 2012 at 10:47

1 Answer 1

2

I ended up querying explicitly for the full set of sub-entities in my custom repository method...

I changed this query :

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

to :

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

I guess Doctrine's use of Proxy objects are not all that transparent...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.