Blog: Propel 1.5.2 Released

The Propel Team – 17 June 2010

A little more than a month after the previous minor release, the Propel team is proud to announce version 1.5.2. This version is backwards compatible with the 1.5 branch, fixes more than 20 bugs, and adds a handful of features. The detailed changelog is available in the Propel 1.5 documentation, so let’s focus on the enhancements.

Namespace support

Propel can now generate Model classes using Namespaces, so your Propel Models will integrate smoothly into any PHP 5.3 application. This feature is optional, so there will be no change for your PHP 5.2 applications. Propel can even use the namespace to distribute model classes into subdirectories, so PHP5.3-flavored autoloaders will play well with your Propel classes.

This feature is documented in a new tutorial called “How to Use PHP 5.3 Namespaces”, available in the ‘Docs’ tab of the Propel website.

<?phpuse Bookstore\AuthorQuery;$author = AuthorQuery::create()  ->useBookQuery()    ->filterByPrice(array('max' => 10))  ->endUse()  ->findOne();

Aggregate Column Behavior

If you follow this blog, you may have discovered How to keep an aggregate column up-to-date and How to write a behavior based on the previous example. Well, it turns out that the code showcased in these tutorials is very useful, so we’ve added to the Propel core behaviors, together with unit tests and complete documentation. Now you won’t ever have to worry about denormalizing your model for better performance and simpler queries.

<table name="post">  <column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />  <column name="title" type="VARCHAR" required="true" primaryString="true" />  <behavior name="aggregate_column">    <parameter name="name" value="nb_comments" />    <parameter name="foreign_table" value="comment" />    <parameter name="expression" value="COUNT(id)" />  </behavior></table>

ModelCriteria::findOneOrCreate()

This new method does exactly what its name says: it issues a findOne() query, and if the database returns no result, then it creates a record and populates it using the filters/conditions applied to the query. This is particularly useful for cross-reference tables in many-to-many relationships. This method is documented in the ModelCriteria Reference.

<?php$bookTag = BookTagQuery::create()  ->filterByBook($book)  ->filterByTag('crime')  ->findOneOrCreate();

Simple Templating Engine For Behaviors

If you’ve dug into core behaviors, you may have found the code hard to read and debug. Thanks to a simple templating engine, future behaviors will offer a much cleaner syntax, without the need to worry about escaping dollars and quotes. The new aggregate_column is built using this technique, which you can learn in the new How to Write a Behavior Tutorial.

/** * Computes the value of the aggregate column <?php echo $column->getName() ?>  * * @param PropelPDO $con A connection object * * @return mixed The scalar result from the aggregate query */public function compute<?php echo $column->getPhpName() ?>(PropelPDO $con){  $stmt = $con->prepare('<?php echo $sql ?>');<?php foreach ($bindings as $key => $binding): ?>  $stmt->bindValue(':p<?php echo $key ?>', $this->get<?php echo $binding ?>());<?php endforeach; ?>  $stmt->execute();  return $stmt->fetchColumn();}

Query Comments

If you need to ‘tag’ a query in order to be able to find it later in your logs, the best way is to add an SQL comment to it. It’s now easy thanks to the ModelCriteria::setComment() method. It works for SELECT queries as well as DELETE and UPDATE queries. You will find an example in the ModelCriteria Reference.

<?phpAuthorQuery::create()  ->setComment('Author Deletion')  ->filterByName('Leo Tolstoy')  ->delete($con);// The comment ends up in the generated SQL query// DELETE /* Author Deletion */ FROM `author` WHERE author.NAME = 'Leo Tolstoy'

Miscellaneous

The Model autoloader has been refactored to separate the autoloading of core Propel classes and Model classes. That should produce a small speed bump, and an easier integration of Propel into third-party libraries.

Also, exceptions thrown while executing a query should now be more useful, since the complete SQL query is now included in the PropelException message.

The XSD for the schema.xml has been greatly completed; it makes writing a schema with an IDE extremely fast an error-proof.

Upgrade

You can see the enhancements of the 1.5.2 release as an incentive to upgrade quickly. Propel keeps getting better every day, and we hope that this short release cycle will help you to motivate your fellow developers to adopt Propel.

Subversion tag

> svn checkout http://svn.propelorm.org/tags/1.5.2

PEAR package

> sudo pear upgrade propel/propel-generator> sudo pear upgrade propel/propel-runtime

Download

http://files.propelorm.org/propel-1.5.2.tar.gz

http://files.propelorm.org/propel-1.5.2.zip