Working with Models (Advanced)
Working with Models (Advanced)
Hydration Modes
As mentioned previously, resultsets are collections of complete objects, this means that every returned result is an object representing a row in the database. These objects can be modified and saved again to persistence:
use Store\Toys\Robots; $robots = Robots::find(); // Manipulating a resultset of complete objects foreach ($robots as $robot) { $robot->year = 2000; $robot->save(); }
Sometimes records are obtained only to be presented to a user in read-only mode, in these cases it may be useful to change the way in which records are represented to facilitate their handling. The strategy used to represent objects returned in a resultset is called ‘hydration mode’:
use Phalcon\Mvc\Model\Resultset; use Store\Toys\Robots; $robots = Robots: