We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

find, findFirst hydration

Is it possible to get a simple array using find and findFirst? Model::find(array("hydration" => Resultset::HYDRATE_ARRAYS)) seem to return array of objects.

If there is no way currently, would you please implement it?

Also it would be very nice to have shortcut methods for fetching different types of results, much like in PDO.

  1. a function to get first field from the first row, useful when I select single value from DB
  2. a function to fetch key => value pairs, with pdo you can achieve this using FETCH_KEY_PAIR, which is very handy sometimes.

Forgive my ignorance, do you mean you want to fetch the findFirst as array? I ussally do that like this

$theModel = Model::findFirst(...);
$theArray = $theModel ? $theModel->toArray() : null;


12.2k

I do this currently, however I would be glad to have options similar with Doctrine 1 (I haven't used Doctrine 2, probably it has the same): HYDRATE_OBJECT, HYDRATE_ARRAY, HYDRATE_ARRAY_SHALLOW. Object is object, array is nested array of an entity and fetched related entries, and shallow array is a single level array of just an entity itself.

Btw, can we create our own hydration classes? Would be also nice.

I see. Yes, It would be great if phalcon has hydrate shallow mode. And what is the index key name that holds the related object? You can propose an NFR to the cphalcon github repo for this.