This plugin simplifies the code behind working with large result sets in Propel.
It provides a utility class that performs "lazy hydration" of a result set, and
which implements the Iterator interface, allowing its use in foreach loops.

Developers

License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Changelog for release 0.1.1 - 16/05/2009

Other releases

Release 0.1.1 - 16/05/2009

sfPropelLazyHydrationIteration plugin

The sfPropelLazyHydrationIterationPlugin is a Symfony plugin designed for Propel 1.2-based projects that make use of "lazy hydration" to deal with larger database result sets. Specifically, it provides a higher-level API for doing so, that relieves your application's own business logic from dealing with Creole's ResultSet objects.

Usage

The main class in the plugin is the sfPropelLazyHydrationIterator. This class actually implements the "lazy hydration" example it replaces internally, but hides it away into an object that implements PHP's Iterator interface (more info).

Let's take a very simple look at the class in use:

// prepare the Criteria to describe the query you'd like to issue$crit = new Criteria();
// let's identify the name of the model class we're going to retrieve$model_class = 'Author';
// finally, let's create the iterator$authors = new sfPropelLazyHydrationIterator($model_class, $crit);
// finally, let's iterate over each Author that matches our queryforeach($autorsas$author){// do something with $author}

The sample above shows the most basic use of the sfPropelLazyHydrationIterator. The constructor requires at least two parameters: the name of the Propel model class that must be retrieved, and a Criteria object.

The sfPropelLazyHydrationIterator also allows for the specification of a particular Propel Connection, as follows:

When adding a doSelectLazy() method to each peer in your model, do note that you'll have to vary the first parameter of the constructor call, which instead of 'Author' should reflect the peer's own model class counterpart.

Considerations

It may seem tempting to replace all your doSelect() invocations with doSelectLazy() calls, but there are a couple of points to consider before you do, since doSelect() returns an array of objects, while doSelectLazy() returns an Iterator which is not an array.

Note the use of PHP functions such as count(), and empty(). Since the sfPropelLazyHydrationIterator isn't a PHP array, these techniques aren't suitable. Luckily, the class does provide a number of methods that provide parallel utility:

All this to say that you should be able to accomplish all the same types of things, regardless of which selection mechanism you decide to use, but that they are not transparently interchangeable with each other in existing code.

Known Issues

This plugin does not yet work with Propel 1.3.

It is not presently possible to perform a PEAR install into a Symfony 1.0 project (1.1 works great, though). Here is what you will likely see: