Blog > Propel 1.6 gets ENUM, ARRAY, and OBJECT Column Types

The Propel Team – 09 December 2010

Dealing with complex data will become easier with Propel 1.6. Complex column types have landed in the 1.6 branch, and they offer a clean interface to store and retrieve ENUM, ARRAY, and OBJECT values. Here is a quick example:

<table name="book">
  <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" />
  <column name="title" type="VARCHAR" />
  <column name="style" type="ENUM" valueSet="novel, essay, poetry" />
  <column name="tags" type="ARRAY" />

The getters and setters for the style and tags columns make it easy to work with a predefined value set, or a list of values:

$book = new Book();
$book->setTitle('Pride and Prejudice');
// ENUM columns only accept values from the valueSet - other values throw an Exception
// ARRAY columns accept an array of scalar values
$book->setTags(array('satire', '19th century'));

// These properties are persisted to the database through serialization
// And of course, Propel restores them seamlessly through hydration
$book = BookQuery::create()->findOneByTitle('Pride and Prejudice');
echo $book->getStyle(); // novel
echo $book->hasTag('satire'); // true
print_r($book->getTags()); // array('satire', '19th century', 'England');

To be honest, this is a common feature for other ORMs, and Propel is quite late to support these column types. But no other ORM supports searching of records based on complex column values. Thanks to the generated filterByXXX() methods, this is a piece of cake for Propel:

// find books using an ENUM column value
$books = BookQuery::create()
// find books using an ARRAY column value
$books = BookQuery::create()
// find books using an ARRAY column values - ALL, SOME or NONE
$books = BookQuery::create()
  ->filterByTags(array('England', 'satire'), Criteria::CONTAINS_SOME)

And this is not restricted to database platforms that actually support these column types. With Propel, ENUM, ARRAY and OBJECT column types work on MySQL, PostgreSQL, MSSQL, SQLite, and Oracle!

The Propel Documentation already contains a full chapter describing this feature, together with example usage. And of course, these features are fully unit tested, so you can use them right away.