czogori/propel-postgres-hstore-behavior

Storage of key-value items using Postgres hstore.

v0.9.1 2014-01-18 15:05 UTC

README

Build Status Latest Stable Version

Storage of key-value items using Postgres hstore.

Installation

First of all you have to install postgresql-contrib and create hstore extension.

CREATE EXTENSION hstore;

After that download code using composer:

{
    "require": {        
        "czogori/propel-postgres-hstore-behavior": "dev-master"
    }
}

And put undermentioned entry to your propel.ini or build.properties configuration file:

propel.behavior.hstore.class = path.to.PostgresHstoreBehavior

Usage

Table definition - schema.xml file:

<table name="book" phpName="Book">    
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="title" type="varchar" size="255" required="true" />
        <column name="extra_parameters" type="varchar" required="false" />    
        <behavior name="hstore">
            <parameter name="column_name" value="extra_parameters" />       
        </behavior>
</table>

Now you can use hstore behavior.

$book = new Book();
$book->setTitle('Foo and Bar');
// you can set params as array
$book->setExtraParameters(array('language' => 'polish'));
// or like this
$book->setLanguage('polish');
$book->save();

echo $book->getLanguage();
echo $book->getExtraParameters('language');