New hydration modes for Doctrine 1.1

Posted over 3 years ago by romanb

I would like to announce the addition of two new hydration modes to the 1.1 branch that will be included in the 1.1 release.

  • HYDRATE_SCALAR - flat array where the key is made up of the query component alias + field name. This method offers access to all the same data in a flat array and the hydration process for it is much faster.
  • HYDRATE_SINGLE_SCALAR - Allows you to easily access single value results, bypassing the expensive hydration process.

We feel that they fill an important gap between HYDRATE_NONE and HYDRATE_RECORD/HYDRATE_ARRAY.

You can read more about the new hydration modes in the docs. Starting at "Fetching data". You can also take a look at the new test case.

We encourage everyone to try them out and give us some feedback. Note that this is a feature preview and the implementation and syntax might change (or not) until the final 1.1 release, depending on how many issues arise and depending on the feedback.


Comments (7) [ add comment ]

Update Posted by Robert Henniger about over 3 years ago.

Thanks, thats a great improvement. It was very time wasting to write own "hydration" on top of the output of doctrine. Now the HYDRATE_SCALAR fits my needs. Thanks for this great framework and the perfect support. Robert

Great improvement Posted by nodkz about over 3 years ago.

Cool! It is exactly that thing, which takes forward place in our system.

GREAT Posted by Hélder Silva about over 3 years ago.

What a relief :P i'm currently using HYDRATE_NONE in one function of my code, but this will help me remove some of my old raw sql code.

Many thanks.

P.S:I'm trying to make my companie to make some notation to the doctrine project, since it help'ed us alot :)

Broken LInk Posted by Daniel about over 2 years ago.

The link "in the docs" is broken .. i wish i could read more about Hydration modes....

Broken link Posted by about about about 1 year ago.

http://www.doctrine-project.org/projects/orm/1.2/docs/manual/data-hydrators/en#data-hydrators

Do not duplicate the row Posted by samuel about about 1 year ago.

Imagine we have user with emails (more than one). The query 'select u e from User u leftJoin u.emails' will produce one row for each email the user has. I would like to get instead one row for each user with the array of emails.

So instead of something like:

0 => array(3) { "u_id" => int(1) "u_name" => string(4) "John" "e_email" => string(13) "john@john.com" } 1 => array(3) { "u_id" => int(1) "u_name" => string(4) "John" "e_email" => string(13) "john@john.org" }

I would like to get:

0 => array(3) { "u_id" => int(1) "u_name" => string(4) "John" "e_email" => array(2) { string(13) "john@john.com" string(13) "john@john.org" } }

So, I want scalar results, but, if there is more than one result for some property, I would like to have it in the array, and do not duplicate the row.

Do duplicate the row Posted by davo about about 1 year ago.

The above idea from samuel is silly. That just complexifies the hydration code in Doctrine and few people will want it: SQL doesn't work like that.

Create Comment