How can I specify HYDRATE_ARRAY in the table convenience methods?
With Doctrine 2, is there any way to specify HYDRATE_ARRAY
when I use the convenience 开发者_C百科methods EntityRepository::find
or EntityRepository::findOneById
? Do I have to write my own DQL query, and use that instead?
I'm not sure, but I think you can't.
You will have to write your own DQL, or fetch an object and later serialize it to an array.
Second approach is probably slower, but it comes handy for testing environment. I have used beberleis serialization class found here.
It works ok, except you can't serialize one-to-many and many-to-many relations in an object, in other words anything that should serialize as an collection of objects.
Btw. if you don't have php5.4, just replace the trait
with an abstract class
, and have all your model object inherit from that class
精彩评论