Collections And On-Demand Hydration
The advantage of using a collection instead of an array is that Propel can hydrate model objects on demand. Using this feature, you'll never fall short of memory when retrieving a large number of results. Available through the setFormatter() method of Model Queries, on-demand hydration is very easy to trigger:
<?php
$authors = AuthorQuery::create()
->limit(50000)
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
->find();
foreach ($authors as $author) {
echo $author->getFirstName();
}
1) What is the meaning of "Hydration" here?
2) what is the difference between collection and array?
Source : Propel @1.6
1.Hidration
A means to improve performance by "filling" your Class/Object with the row data just when you need it.
Instead of doing "SELECT * FROM SomeTable"
from a very large table, Propel will initially fire off "SELECT ID FROM SomeTable"
, then inside the loop, then do "SELECT [COLUMS] FROM SomeTable WHERE ID=[CurrentID]"
, hence "On Demand"
2. Collection vs Array Array is just the normal array, whereas a PropelCollection is an Object of Objects, which has a lot of stuff available such as:
->isOdd()
, etc.$object->count()
->toYAML()
, ->toCSV()
, ->toXML()
Each item in the collection is a PropelObject, so you can still fetch data with ->getColumn()
inside your loop. Documentation