I'm attempting to use the columns parameter to avoid selecting unnecessary data from my database. The columns selected could be none, a single column or anything inbetween depending on input parameters. I've overwritten the toArray method of my base class and extending classes and I have a problem when using the columns parameter in that object of my class types are no longer returned. I tried setting hydration to objects but it does nothing. I've read the documentation at https://docs.phalcon.io/en/latest/reference/models.html#finding-records and I understand why partial objects are returned. However, I don't understand why a partial record is returned when I explicitally set the hydration. This inconsistency can be corrected with the code below.
$robots = Robot::find(['columns' => 'id,name']);
$arrayOfRobots = [];
foreach($robots as $robot) {
$robotData = $robot->toArray();
$robot = new Robot();
$robot->assign($robotData);
$arrayOfRobots[] = $robot;
}
This workaround though must be applied conditionally depending on if the columns input exists.
Is there a way to force Phalcon to respect the hydration method and why does the hydration documentation not note that it is ignored when using the columns parameter?