ZF2 - How to use the Hydrator/exchangeArray() to populate a nested object
Posted
by
Dominic Watson
on Stack Overflow
See other posts from Stack Overflow
or by Dominic Watson
Published on 2012-10-06T21:34:14Z
Indexed on
2012/10/06
21:37 UTC
Read the original article
Hit count: 229
I've got an object with values that are stored in my database. My object also contains another object which is stored in the database using just the ID of it (foreign key).
http://framework.zend.com/manual/2.0/en/modules/zend.stdlib.hydrator.html
Before the Hydrator/exchangeArray
functionality in ZF2 you would use a Mapper to grab everything you need to create the object. Now I'm trying to eliminate this extra layer by just using Hydration/exchangeArray
to populate my objects but am a bit stuck on creating the nested object.
Should my entity have the Inner object's table injected into it so I can create it if the ID of it is passed to my 'exchangeArray' ?
Here are example entities as an example.
// Village
id, name, position, square_id
// Map Square
id, name, type
Upon sending square_id to my Village's exchangeArray() function. It would get the mapTable and use hydrator to pull in the square using the ID I have.
It doesn't seem right to be to have mapper instances inside my entity as I thought they should be disconnected from anything but it's own entity specific parameters and functionality?
© Stack Overflow or respective owner