I am designing a room booking system which has nine entities, which all relate to each other. In this specific instance I am retrieving 10-30 rows from the entity entry which has 25 properties. Each entry has one room which has 10 properties. I need all of the entry information as well as entry->room->id and entry->room->name. But it seems like doctrine is loading the entire room when I use Query::HYDRATE_ARRAY. It seems to be lazy-loading in Query::HYDRATE_OBJECT more easily.
So, I am wondering if using the Query::HYDRATE_OBJECT mode is faster or “better” than Query::HYDRATE_ARRAY / Query::HYDRATE_SCALAR/ Query::HYDRATE_SINGLE_SCALAR. Since I am reusing some older code I’d like to use HYDRATE_ARRAY but only if it won’t slow the application down.
My 2 cents:
HYDRATE_OBJECTis best for when you plan on using a lot of business logic with your objects. Especially if you’re doing a lot of data manipulation. It’s also probably the slowest (depending on the situation).HYDRATE_ARRAYis usually reserved for when you only need a result and 1 degrees of relational data and it’s going to be used for printing/viewing purposes only.HYDRATE_NONEis another one I use when I’m only selecting a very small subset of data (like one or two fields instead of the entire row). This behaves much like a raw query result would.This might also be of interest http://www.doctrine-project.org/2010/03/17/doctrine-performance-revisited.html
This is from the 1.2 docs but I think the Hydration tips apply in 2.0 http://doctrine.readthedocs.org/en/latest/en/manual/improving-performance.html
On using
HYDRATE_ARRAY: