Aliasing fields using partial object syntax + array hydrator in doctrine 2

Tags: , , ,

Is there any way to alias fields when using partial object syntax in Doctrine 2?

I know I can do this:

     ' AS id',
     'user.firstName AS first_name',
     'user.lastName AS last_name',
     ' AS email',
     'user.dateCreated AS date_created'

However I need to use the partial object syntax in order for doctrine to retrieve the result in a nested relational heirarchy:

    ->select('PARTIAL team.{id, name, dateCreated}, s, PARTIAL e.{id, name}')
    ->innerJoin('team.session', 's')
    ->innerJoin('s.event', 'e')

I dug around in DoctrineORMInternalHydrationArrayHydrator but didn’t see any hooks or anything, and it doesn’t look like Doctrine has a postSelect event or something that would allow me to implement my own mutation.

Thanks for any help!


Not very efficient, but I ended up subclassing the ArrayHydrator and mutating the keys myself.

Hopefully there is a better way, if not I hope this helps someone

Source: stackoverflow