Getting started with Propel

Propel Installation

Composer

Create a new composer.json file at the root of your project’s directory:

{
    "require": {
        "propel/propel": ">= 2.0"
    }
}

Download Composer:

$ wget http://getcomposer.org/composer.phar
# If you haven't wget on your computer
$ curl -s http://getcomposer.org/installer | php

Install dependencies:

$ php composer.phar install

Git

$ git clone git://github.com/propelorm/Propel2 vendor/propel

To update Propel:

$ cd myproject/vendor/propel
$ git pull

Tarball

$ cd myproject/vendor
$ wget http://files.propelorm.org/propel-2.0.0.tar.gz
$ tar zxvf propel-2.0.0.tar.gz
$ mv propel-2.0.0 propel

Propel basic use

Generating Propel model from database

Go to the project directory anywhere on your filesystem:

$ cd MyProject

Run the reverse task to generate the schema.xml specifying your database credentials:

$ propel reverse "mysql:host=localhost;dbname=db;user=root;password=pwd"

Now you have a schema.xml file in the MyProject/ project directory.

For more details check the documentation.

Creating database tables from Propel model

Set Up Build Configuration

Propel expects the build configuration to be stored in a file called build.properties, and stored at the same level as the schema.xml. Here is an example for a MySQL database:

# Database driver
propel.database = mysql

# Project name
propel.project = MyProject

Use the propel Script To Build The SQL Code

$ cd /path/to/my/project
$ propel sql:build

Generate Model Classes

$ propel model:build

For more details check the documentation.

Using Propel with Symfony2

Installation

{
    "require": {
        // ...
        "propel/propel-bundle": "1.2.*"
    }
}
Tip

Different bundle version may be needed for different Symfony2 version. Check PropelBundle for details.

Git, SVN, Git submodules, or the Symfony vendor management (deps file):

Clone this bundle in the vendor/bundles/Propel directory:

> git submodule add https://github.com/propelorm/PropelBundle.git vendor/bundles/Propel/PropelBundle

Checkout Propel and Phing in the vendor directory:

> svn checkout http://svn.github.com/propelorm/Propel.git vendor/propel
> svn checkout http://svn.phing.info/tags/2.4.6/ vendor/phing

Instead of using svn, you can clone the unofficial Git repositories:

> git submodule add https://github.com/phingofficial/phing.git vendor/phing
> git submodule add https://github.com/propelorm/Propel.git vendor/propel

Instead of doing this manually, you can use the Symfony vendor management via the deps file. If you are using a Symfony2 2.x.x version (actually, a version which is not 2.1 or above), be sure to deps.lock the PropelBundle to a commit on the 2.0 branch, which does not use the Bridge

Bundle registration

<?php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Propel\PropelBundle\PropelBundle(),
    );

    // ...
}

Register the PropelBundle namespace in app/autoload.php if you are not using Composer:

<?php
$loader->registerNamespaces(array(
    // ...
    'Propel' => __DIR__.'/../vendor/bundles',
));
$loader->registerPrefixes(array(
    // ...
    'Phing'  => __DIR__.'/../vendor/phing/classes/phing',
));

Now, you can build your model classes, and SQL by running the following command:

> php app/console propel:build [--classes] [--sql] [--insert-sql]

To insert SQL statements, use the propel:sql:insert command:

> php app/console propel:sql:insert [--force]

Configuration

Symfony configuration

In order to use Propel configure few parameters in app/config/config.yml file.

If you are not using Composer, add this configuration:

# in app/config/config.yml
propel:
    path:       "%kernel.root_dir%/../vendor/propel"
    phing_path: "%kernel.root_dir%/../vendor/phing"

Basic Configuration

If you have just one database connection, use of this parameters is recommended:

# app/config/config*.yml
# define the parameters in app/config/parameters.yml
propel:
    dbal:
        driver:               %database_driver%
        user:                 %database_user%
        password:             %database_password%
        dsn:                  %database_driver%:host=%database_host%;dbname=%database_name%;charset=UTF8
        options:              {}
        attributes:           {}

More details can be found in Propel documentation

Attributes, Options, Settings

# app/config/config*.yml
propel:
    dbal:
        default_connection:         default
        connections:
            default:
                # ...
                options:
                    ATTR_PERSISTENT: false
                attributes:
                    ATTR_EMULATE_PREPARES: true
                settings:
                    charset:        { value: UTF8 }
                    queries:        { query: "INSERT INTO BAR ('hey', 'there')" }

Logging

# in app/config/config.yml
propel:
    logging:    %kernel.debug%

Propel Configuration

You can add a app/config/propel.ini file in your project to specify some configuration parameters.

By default the PropelBundle is configured with the default parameters:

# Enable full use of the DateTime class.
# Setting this to true means that getter methods for date/time/timestamp
# columns will return a DateTime object when the default format is empty.
propel.useDateTimeClass = true

# Specify a custom DateTime subclass that you wish to have Propel use
# for temporal values.
propel.dateTimeClass = DateTime

# These are the default formats that will be used when fetching values from
# temporal columns in Propel. You can always specify these when calling the
# methods directly, but for methods like getByName() it is nice to change
# the defaults.
# To have these methods return DateTime objects instead, you should set these
# to empty values
propel.defaultTimeStampFormat =
propel.defaultTimeFormat =
propel.defaultDateFormat =

# A better Pluralizer
propel.builder.pluralizer.class = builder.util.StandardEnglishPluralizer

Configure your schema

Database manipulation

Create a database:

> php app/console propel:database:create [--connection[=""]]

Drop a database:

> php app/console propel:database:drop [--connection[=""]] [--force]

Migrations

Generates SQL diff between the XML schemas and the current database structure:

> php app/console propel:migration:generate-diff

Executes the migrations:

> php app/console propel:migration:migrate

Executes the next migration up:

> php app/console propel:migration:migrate --up

Executes the previous migration down:

> php app/console propel:migration:migrate --down

Lists the migrations yet to be executed:

> php app/console propel:migration:status

Table Manipulations

You can drop one or several tables:

> php app/console propel:table:drop [--force] [--connection[="..."]] [table1] ... [tableN]

Working with existing databases

Run the following command to generate an XML schema from your default database:

> php app/console propel:reverse

You can define which connection to use:

> php app/console propel:reverse --connection=default

This will create your schema file under app/propel/generated-schemas.

The Fixtures

Loading Fixtures:

> php app/console propel:fixtures:load [-d|--dir[="..."]] [--xml] [--sql] [--yml] [--connection[="..."]] [bundle]

You can pass a bundle name to load fixtures from it:

> php app/console propel:fixtures:load @AcmeDemoBundle

Propel Model Elements

Schema file structure

Propel uses one schema definition file for each package. The file is structured like this:

XML
YML
Links
<?xml version="1.0"?>
<database name="bookCatalogue">
  <table name="book" />
  <table name="itemRecordHasAuthor" isCrossRef="true" />
  <table name="itemRecord" />
  <table name="author" />
</database>
propel:
  book:
  itemRecordHasAuthor:
  itemRecord:
  author:
Propel schema as ER diagram automatically generated by Skipper.

Generated by Skipper

You can go and see how to do this in few clicks.

Database element

Database element (package) with all properties defined:

XML
YML
Links
<database 
 name="bookCatalogue" 
 baseClass="propel.om.BaseObject" 
 basePeer="propel.util.BasePeer" 
 defaultIdMethod="native" 
 defaultPhpNamingMethod="underscore" 
 heavyIndexing="true" 
 namespace="BookCatalogue" 
 package="Library" 
 schema="/SQLSchema/" 
 tablePrefix="/Prefix/">
 ....
</database>
propel:
  _attributes:
    baseClass: propel.om.BaseObject
    basePeer: propel.util.BasePeer
    defaultIdMethod: native
    defaultPhpNamingMethod: underscore
    heavyIndexing: true
    namespace: BookCatalogue
    package: Library
    schema: /SQLSchema/
    tablePrefix: /Prefix/
Propel schema as ER diagram automatically generated by Skipper.

Generated by Skipper

You can go and see how to do this in few clicks.

Table

Simple table

Simple table element with a primary key and several fields:

XML
YML
Links
<table name="author">
  <column name="id" type="integer" size="255" required="true" autoIncrement="true" primaryKey="true"/>
  <column name="firstName" type="Varchar" required="true"/>
  <column name="lastName" type="Varchar" required="true"/>
  <column name="birthDate" type="Varchar"/>
</table>
  author:
    id:
      type: integer
      size: 255
      required: true
      autoIncrement: true
      primaryKey: true
    firstName:
      type: Varchar
      required: true
    lastName:
      type: Varchar
      required: true
    birthDate:
      type: Varchar
Propel entity displayed in Skipper ER diagram.

Generated by Skipper

Table with all options defined

Table element with all options defined:

XML
YML
Links
<table 
 name="itemRecord" 
 abstract="true" 
 allowPkInsert="true" 
 baseClass="propel.om.BaseObject2" 
 basePeer="propel.om.BasePeer2" 
 heavyIndexing="true" 
 idMethod="none" 
 isI18N="true" 
 i18nTable="language" 
 namespace="\records" 
 package="Records" 
 phpNamingMethod="underscore" 
 phpName="ItemRecord" 
 readOnly="true" 
 reloadOnInsert="true" 
 reloadOnUpdate="true" 
 schema="/Schema/" 
 skipSql="false" 
 treeMode="MaterializedPath">
  <column name="id"/>
  ....
  <vendor type="mysql">
    <parameter name="Engine" value="InnoDB"/>
  </vendor>
</table>  
  itemRecord:
    _attributes:
      abstract: true
      allowPkInsert: true
      baseClass: propel.om.BaseObject2
      basePeer: propel.om.BasePeer2
      heavyIndexing: true
      idMethod: none
      isI18N: true
      i18nTable: language
      namespace: \records
      package: Records
      phpNamingMethod: underscore
      phpName: ItemRecord
      readOnly: true
      reloadOnInsert: true
      reloadOnUpdate: true
      schema: /Schema/
      skipSql: false
      treeMode: MaterializedPath
Propel entity and its association shown is Skipper visual editor.

Generated by Skipper

You can go and see how to do this in few clicks.

Id

Primary key definition:

XML
YML
Links
<column name="id" type="integer" size="255" required="true" autoIncrement="true" primaryKey="true"/>
<unique name="IX_UQ_itemRecord_id">
  <unique-column name="id"/>
</unique>
  itemRecord:
    id:
      type: integer
      size: 255
      required: true
      autoIncrement: true
      primaryKey: true
    _uniques:
      IX_UQ_itemRecord_id: [id]
Propel entity imported to Skipper visual model from schema definitions.

Generated by Skipper

Primary key with all base properties set:

XML
YML
Links
<column 
 name="id" 
 type="integer" 
 size="255" 
 required="true" 
 autoIncrement="true" 
 primaryKey="true" 
 defaultExpr="/defaultSQLexpression/" 
 description="this is primary key" 
 inheritance="single" 
 lazyLoad="true" 
 phpName="Id" 
 phpNamingMethod="underscore" 
 phpType="integer" 
 primaryVarchar="true" 
 scale="2" 
 onDelete="RESTRICT" 
 peerName="/peer name/" 
 isCulture="true" 
 inputValidator="/input validator/" 
 sqlType="integer" 
 tableMapName="/table map name/"
 >
  <vendor type="">
    <parameter name="Engine" value="InnoDB"/>
    <parameter name="Charset" value="utf8"/>
  </vendor>
</column>
<unique name="IX_UQ_itemRecord_id">
  <unique-column name="id"/>
</unique>
  itemRecord:
    id:
      type: integer
      size: 255
      required: true
      autoIncrement: true
      primaryKey: true
      defaultExpr: /defaultSQLexpression/
      description: this is primary key
      inheritance: single
      lazyLoad: true
      phpName: Id
      phpNamingMethod: underscore
      phpType: integer
      primaryVarchar: true
      scale: 2
      onDelete: RESTRICT
      peerName: /peer name/
      isCulture: true
      inputValidator: /input validator/
      sqlType: integer
      tableMapName: /table map name/
Propel entity imported to Skipper visual model from schema definitions.

Generated by Skipper

You can go and see how to do this in few clicks.

Column

Regular column definition:

XML
YML
Links
<column name="name" type="Varchar" size="255" required="true"/>
  itemRecord:
    name:
      type: Varchar
      size: 255
      required: true
Propel entity and selected field in Skipper ER diagram.

Generated by Skipper

Column with all options set:

XML
YML
Links
<column 
 name="name" 
 description="regular field" 
 type="Varchar" 
 size="255" 
 required="true" 
 valueSet="Frank, Carl, Victor, Bob" 
 defaultExpr="/defaultSQLexpression/" 
 defaultValue="name" 
 inheritance="single" 
 inputValidator="/inputValidator/" 
 lazyLoad="true" 
 phpName="Name" 
 phpNamingMethod="underscore" 
 phpType="Varchar" 
 primaryVarchar="true" 
 scale="0" 
 tableMapName="/table map name/" 
 sqlType="/SQL type used in CREATE and ALTER statements/" 
 peerName="/peer name/" 
 onDelete="CASCADE" 
 isCulture="true"
 >
       <vendor type="">
        <parameter name="Engine" value="InnoDB"/>
        <parameter name="Charset" value="utf8"/>
      </vendor>
    </column>
  itemRecord:
    name:
      description: regular field
      type: Varchar
      size: 255
      default: Frank
      required: true
      valueSet: Frank, Carl, Victor, Bob
      defaultExpr: /defaultSQLexpression/
      defaultValue: name
      inheritance: single
      inputValidator: /inputValidator/
      lazyLoad: true
      phpName: Name
      phpNamingMethod: underscore
      phpType: Varchar
      primaryVarchar: true
      scale: 0
      tableMapName: /table map name/
      sqlType: /SQL type used in CREATE and ALTER statements/
      peerName: /peer name/
      onDelete: CASCADE
      isCulture: true
Propel entity and selected field in Skipper ER diagram.

Generated by Skipper

Column with all validators listed:

XML
Links
<column name="item" type="Varchar"/>
<validator column="item">
  <rule name="/validator class/" value="/value/" message="/custom message/"/>
  <rule name="match" value="/regexp/" message="Does match the regexp"/>
  <rule name="maxLength" value="1024" message="exceeded maxlenght"/>
  <rule name="maxValue" value="1025" message="exceeded max value"/>
  <rule name="minLength" value="4" message="shorter than min lenght"/>
  <rule name="minValue" value="5" message="smaller than min value"/>
  <rule name="notMatch" value="/regexp/" message="does not match the regexp"/>
  <rule name="/validator name/" value="/use this for other propel validators/" message="/custom message/"/>
  <rule name="required" message="column is required"/>
  <rule name="type" value="integer" message="wrong type"/>
  <rule name="unique" message="not unique"/>
  <rule name="validValues" value="book|magazine" message="is valid value"/>
</validator>

You can go and see how to do this in few clicks.

Index

Unique index

Unique index definition:

XML
YML
Links
<table name="author">
  <column name="firstName"/>
  <column name="lastName"/>
  <column name="birthDate"/>
  <unique name="ix_first_name_last_name_date">
    <unique-column name="firstName"/>
    <unique-column name="lastName"/>
    <unique-column name="birthDate"/>
  </unique>
</table>
  author:
    firstName:
    lastName:
    birthDate:
    _uniques:
      ix_first_name_last_name_date: [firstName, lastName, birthDate]
Propel entity in Skipper visual model

Generated by Skipper

Non-unique indexes

Non-unique index:

XML
YML
Links
<table name="author">
  <column name="firstName"/>
  <column name="lastName"/>
  <index name="ix_name_last">
    <index-column name="lastName"/>
  </index>
</table>
  author:
    firstName:
    lastName:
    _indexes:
      ix_name_last: [lastName]
Propel entity in Skipper visual model

Generated by Skipper

You can go and see how to do this in few clicks.

Association

One to One

One to one owner side:

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<foreign-key foreignTable="ean">
		<reference foreign="id" local="eanId"/>
	</foreign-key>
</table>
  itemRecord:
    id:
      primaryKey: true
    eanId:
      type: integer
      foreignTable: ean
      foreignReference: id
Propel one to one association in Skipper ER diagram.

Generated by Skipper

One to one inverse side:

XML
YML
Links
<table name="ean">
	<column name="id" primaryKey="true"/>
</table>
  ean:
    id:
      primaryKey: true
Propel one to one association imported from schema definition files.

Generated by Skipper

Many to One

Many to one owner side:

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<foreign-key foreignTable="publisher">
		<reference foreign="id" local="publisherId"/>
	</foreign-key>
</table>
  itemRecord:
    id:
      primaryKey: true
    publisherId:
      type: integer
      size: 255
      required: true
      foreignTable: publisher
      foreignReference: id
Propel many to one association in Skipper ER diagram.

Generated by Skipper

Many to one inverse side:

XML
YML
Links
<table name="publisher">
	<column name="id" primaryKey="true"/>
	<unique name="IX_UQ_publisher_id">
		<unique-column name="id"/>
	</unique>
</table>
  publisher:
    id:
      primaryKey: true
    _uniques:
      IX_UQ_publisher_id: [id]
Propel many to one association imported from schema definition files.

Generated by Skipper

Association with all options enabled

Many to one owner side with all properties:

XML
YML
Links
<table name="itemRecord">
  <column name="id" primaryKey="true"/>
  <column name="publisherId" type="integer" size="255" required="true"/>
  <unique name="IX_UQ_itemRecord_id">
    <unique-column name="id"/>
  </unique>
  <foreign-key 
   foreignTable="publisher" 
   defaultJoin="Criteria::INNER_JOIN" 
   foreignSchema="/foreign schema name/" 
   onDelete="SETNULL" onUpdate="CASCADE" 
   phpName="/php name/" 
   refPhpName="/ref php name/" 
   skipSql="false">
    <reference foreign="id" local="publisherId"/>
  </foreign-key>
</table>
  itemRecord:
    id:
      primaryKey: true
    publisherId:
      type: integer
      size: 255
      required: true
      foreignTable: publisher
      foreignReference: id
      defaultJoin: Criteria::INNER_JOIN
      foreignSchema: /foreign schema name/
      onDelete: RESTRICT
      onUpdate: CASCADE
      phpName: /php name/
      refPhpName: /ref php name/
      skipSql: false
    _uniques:
      IX_UQ_itemRecord_id: [id]
Propel many to one association in Skipper ER diagram.

Generated by Skipper

Many to one inverse side with all properties:

XML
YML
Links
<table name="publisher">
  <column name="id" type="integer" size="255" required="true" autoIncrement="true" primaryKey="true"/>
  <unique name="IX_UQ_publisher_id">
    <unique-column name="id"/>
  </unique>
</table>
  publisher:
    id:
      primaryKey: true
    _uniques:
      IX_UQ_publisher_id: [id]
Propel many to one association imported from schema definition files.

Generated by Skipper

Many to One using non-PK foreign key

Many to one owner side using non-PK foreign key:

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="publisher_name" type="Varchar"/>
	<column name="publisher_vat_code" type="Varchar"/>
	<unique name="IX_UQ_itemRecord_id">
		<unique-column name="id"/>
	</unique>
	<foreign-key foreignTable="publisher">
		<reference foreign="name" local="publisher_name"/>
		<reference foreign="vatCode" local="publisher_vat_code"/>
	</foreign-key>
</table>
  itemRecord:
    id:
      primaryKey: true
    publisher_name:
      type: Varchar
    publisher_vat_code:
      type: Varchar
    _uniques:
      IX_UQ_itemRecord_id: [id]
    _foreignKeys:
      :
        foreignTable: publisher
        references:
          - 
            local: publisher_name
            foreign: name
          - 
            local: publisher_vat_code
            foreign: vatCode
Propel many to one association in Skipper ER diagram.

Generated by Skipper

Many to one inverse side using non-PK foreign key:

XML
YML
Links
<table name="publisher">
	<column name="id" primaryKey="true"/>
	<column name="name" type="Varchar"/>
	<column name="vatCode" type="Varchar" required="true"/>
	<unique name="IX_UQ_publisher_id">
		<unique-column name="id"/>
	</unique>
</table>
  publisher:
    id:
      primaryKey: true
    name:
      type: Varchar
    vatCode:
      type: Varchar
      required: true
    _uniques:
      IX_UQ_publisher_id: [id]
Propel many to one association imported from schema definition files.

Generated by Skipper

You can go and see how to do this in few clicks.

MN Association

Many to Many

Many to many owner side:

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<unique name="IX_UQ_itemRecord_id">
		<unique-column name="id"/>
	</unique>
</table>
  itemRecord:
    id:
      primaryKey: true
    _uniques:
      IX_UQ_itemRecord_id: [id]
Propel many-to-many association in Skipper generated diagram.

Generated by Skipper

Many to many inverse side:

XML
YML
Links
<table name="author">
	<column name="id" primaryKey="true"/>
	<unique name="IX_UQ_author_id">
		<unique-column name="id"/>
	</unique>
</table>
  author:
    id:
      primaryKey: true
    _uniques:
      IX_UQ_author_id: [id]
Propel many-to-many displayed in Skipper visual model.

Generated by Skipper

Many to many with all options enabled:

XML
YML
Links
<table name="authorHasitemRecord" isCrossRef="true">
  <column name="author_id" type="integer" size="255" required="true" primaryKey="true"/>
  <column name="item_record_id" type="integer" size="255" required="true" primaryKey="true"/>
  <foreign-key 
   foreignTable="itemRecord" 
   defaultJoin="Criteria::LEFT_JOIN" 
   onDelete="cascade" 
   onUpdate="cascade" 
   phpName="/php name/" 
   refPhpName="/ref php name/" 
   skipSql="false">
    <reference local="item_record_id" foreign="id"/>
  </foreign-key>
  <foreign-key foreignTable="author" onUpdate="cascade" defaultJoin="Criteria::INNER_JOIN">
    <reference local="author_id" foreign="id"/>
  </foreign-key>
</table>
  authorHasitemRecord:
    _attributes:
      isCrossRef: true
    author_id:
      type: integer
      size: 255
      required: true
      primaryKey: true
      foreignTable: author
      foreignReference: id
      onUpdate: cascade
    item_record_id:
      type: integer
      size: 255
      required: true
      primaryKey: true
      foreignTable: itemRecord
      foreignReference: id
      onDelete: cascade
      onUpdate: cascade

MN Entity

Many-to-many entity.

XML
YML
Links
<table name="authorHasitemRecord" isCrossRef="true">
	<column name="author_id" primaryKey="true"/>
	<column name="item_record_id" primaryKey="true"/>
	<foreign-key foreignTable="itemRecord">
		<reference local="item_record_id" foreign="id"/>
	</foreign-key>
	<foreign-key foreignTable="author">
		<reference local="author_id" foreign="id"/>
	</foreign-key>
</table>
  authorHasitemRecord:
    _attributes:
      isCrossRef: true
    author_id:
      type: integer
      size: 255
      required: true
      primaryKey: true
      foreignTable: author
      foreignReference: id
    item_record_id:
      type: integer
      size: 255
      required: true
      primaryKey: true
      foreignTable: itemRecord
      foreignReference: id
Propel many-to-many imported from schema definitions by Skipper.

Generated by Skipper

Many to Many using non-PK foreign key

Many to many owner side using non-PK foreign keys:

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<unique name="IX_UQ_itemRecord_id">
		<unique-column name="id"/>
	</unique>
</table>
  itemRecord:
    id:
      primaryKey: true
    _uniques:
      IX_UQ_itemRecord_id: [id]
Propel many-to-many association in Skipper generated diagram.

Generated by Skipper

Many to many inverse side using non-PK foreign key:

XML
YML
Links
<table name="author">
	<column name="id" primaryKey="true"/>
	<column name="firstName" type="Varchar" required="true"/>
	<column name="lastName" type="Varchar" required="true"/>
	<unique name="IX_UQ_author_id">
		<unique-column name="id"/>
	</unique>
</table>
  author:
    id:
      primaryKey: true
    firstName:
      type: Varchar
    lastName:
      type: Varchar
    _uniques:
      IX_UQ_author_id: [id]
Propel many-to-many displayed in Skipper visual model.

Generated by Skipper

Many to many entity using non-PK foreign keys:

XML
YML
Links
<table name="authorHasitemRecord" isCrossRef="true">
	<column name="author_first_name" primaryKey="true"/>
	<column name="item_record_id" primaryKey="true"/>
	<column name="author_last_name" primaryKey="true"/>
	<foreign-key foreignTable="itemRecord">
		<reference local="item_record_id" foreign="id"/>
	</foreign-key>
	<foreign-key foreignTable="author">
		<reference local="author_first_name" foreign="firstName"/>
		<reference local="author_last_name" foreign="lastName"/>
	</foreign-key>
</table>
  authorHasitemRecord:
    _attributes:
      isCrossRef: true
    author_first_name:
      type: Varchar
      required: true
      primaryKey: true
    item_record_id:
      type: integer
      size: 255
      required: true
      primaryKey: true
      foreignTable: itemRecord
      foreignReference: id
    author_last_name:
      type: Varchar
      required: true
      primaryKey: true
    _foreignKeys:
      :
        foreignTable: author
        references:
          - 
            local: author_first_name
            foreign: firstName
          - 
            local: author_last_name
            foreign: lastName
Propel many-to-many imported from schema definitions by Skipper.

Generated by Skipper

You can go and see how to do this in few clicks.

Inheritance

Single table inheritance

Single table inheritance parent:

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
  <column name="name"/>
  <column name="cover"/>
  <column name="issue"/>
	<column name="item" type="Varchar" inheritance="single">
		<inheritance key="itemRecord" class="itemRecord"/>
		<inheritance key="book" class="book" extends="itemRecord"/>
		<inheritance key="magazine" class="magazine" extends="itemRecord"/>
		<inheritance key="audioRecord" class="audioRecord" extends="itemRecord"/>
	</column>
</table>
    id:
    name:
    _inheritance:
      column: id
      classes: 
    _inheritance:
      column: name
      classes: 
    _inheritance:
      column: cover
      classes:     
    _inheritance:
      column: issue
      classes: 
    _inheritance:
      column: item
      classes:
        itemRecord: ItemRecord
        book: book
        magazine: magazine
Propel inheritance displayed in Skipper visual model.

Generated by Skipper

Class table inheritance

Class table inheritance parent:

XML
YML
Links
<table name="itemRecord">
  <column name="id" type="integer" primaryKey="true">
	<column name="id" primaryKey="true"/>
	<column name="item" type="Varchar"/>
</table>
  itemRecord:
    id:
      primaryKey: true
    item:
      type: Varchar
    item:
      type: Varchar
Propel inheritance displayed in Skipper visual model.

Generated by Skipper

Class table inheritance child:

XML
YML
Links
<table name="book">
	<column name="id" type="integer" required="true" autoIncrement="true" primaryKey="true"/>
	<column name="cover" type="Varchar"/>
	<unique name="IX_UQ_book_id">
		<unique-column name="id"/>
	</unique>
	<behavior name="delegate">
		<parameter name="to" value="itemRecord"/>
	</behavior>
</table>
  book:
    id:
      type: integer
      required: true
      autoIncrement: true
      primaryKey: true
    cover:
      type: Varchar
    _uniques:
      IX_UQ_book_id: [id]
    _propel_behaviors:
      delegate:
        to: itemRecord
Propel inheritance generated in the Skipper ER diagram.

Generated by Skipper

Concrete table inheritance

Concrete inheritance parent:

XML
YML
Links
<table name="itemRecord">
  <column name="id" type="integer" primaryKey="true">
	<column name="id" primaryKey="true"/>
	<column name="item" type="Varchar"/>
</table>
  itemRecord:
    id:
      primaryKey: true
    item:
      type: Varchar
    item:
      type: Varchar
Propel inheritance displayed in Skipper visual model.

Generated by Skipper

Concrete inheritance child:

XML
YML
Links
<table name="book">
	<column name="id" type="integer" required="true" autoIncrement="true" primaryKey="true"/>
	<column name="cover" type="Varchar"/>
	<unique name="IX_UQ_book_id">
		<unique-column name="id"/>
	</unique>
	<behavior name="concrete_inheritance">
		<parameter name="extends" value="itemRecord"/>
	</behavior>
</table>
  book:
    id:
    cover:
      type: Varchar
    _propel_behaviors:
      concrete_inheritance:
        extends: itemRecord
Propel inheritance generated in the Skipper ER diagram.

Generated by Skipper

You can go and see how to do this in few clicks.

Behaviors

Aggregate column

The aggregate_column behavior keeps a column updated using an aggregate function executed on a related table.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<behavior name="aggregate_column">
		<parameter name="name" value="no_of_copies"/>
		<parameter name="expression" value="COUNT (id)"/>
		<parameter name="foreign_table" value="physicalCopy"/>
	</behavior>
</table>
<table name="physicalCopy">
  <column name="id" primaryKey="true"/>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    _propel_behaviors:
      aggregate_column:
        name: no_of_copies
        expression: COUNT (id)
        foreign_table: physicalCopy

You can go and see how to do this in few clicks.

Alternative coding standards

The alternative_coding_standards behavior changes the coding standards of the model classes generated by Propel to match your own coding style.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<behavior name="alternative_coding_standards">
		<parameter name="brackets_newline" value="true"/>
		<parameter name="remove_closing_comments" value="true"/>
		<parameter name="strip_comments" value="false"/>
		<parameter name="tab_size" value="2"/>
		<parameter name="use_whitespace" value="true"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    _propel_behaviors:
      alternative_coding_standards:
        brackets_newline: true
        remove_closing_comments: true
        strip_comments: false
        tab_size: 2
        use_whitespace: true

You can go and see how to do this in few clicks.

Archivable

The archivable behavior gives model objects the ability to be copied to an archive table.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
    <behavior name="archivable">
		<parameter name="archive_on_insert" value="false"/>
		<parameter name="archive_on_delete" value="false"/>
		<parameter name="archive_on_update" value="false"/>
		<parameter name="archive_class" value="RecordArchive"/>
		<parameter name="archive_table" value="record_archive"/>
		<parameter name="archived_at_column" value="archive_date"/>
		<parameter name="log_archived_at" value="false"/>
	</behavior>
</table>
<table name="record_archive" phpName="RecordArchive">
  <column name="id" required="true" primaryKey="true" type="INTEGER" />
  <column name="title" type="VARCHAR" required="true" primaryString="true" />
  <column name="archived_at" type="TIMESTAMP" />
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    _propel_behaviors:
      archivable:
        archive_on_insert: false
        archive_on_delete: false
        archive_on_update: false
        archive_class: MyBookArchive
        archive_table: special_book_archive
        archived_at_column: archive_date
        log_archived_at: false

You can go and see how to do this in few clicks.

Automatically add PK

The auto_add_pk behavior adds a primary key columns to the tables that don’t have one.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<behavior name="auto_add_pk">
		<parameter name="type" value="integer"/>
		<parameter name="name" value="id"/>
		<parameter name="autoIncrement" value="true"/>
	</behavior>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    _propel_behaviors:
      auto_add_pk:
        type: integer
        name: id
        autoIncrement: true

You can go and see how to do this in few clicks.

i18n

The i18n behavior provides internationalization to any !ActiveRecord object.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="language" type="Varchar"/>
	<behavior name="i18n">
		<parameter name="i18n_columns" value="item,publisherId"/>
		<parameter name="locale_column" value="language"/>
		<parameter name="i18n_table" value="itemRecord"/>
		<parameter name="default_locale" value="fr_FR"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    item:
      type: Varchar
    language:
      type: Varchar
    _propel_behaviors:
      i18n:
        i18n_columns: item,publisherId
        locale_column: language
        i18n_table: itemRecord
        default_locale: fr_FR

You can go and see how to do this in few clicks.

Nested set

The nested_set behavior allows a model to become a tree structure, and provides numerous methods to traverse the tree in an efficient way.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="left" type="Integer"/>
	<column name="right" type="Integer"/>
	<column name="level" type="Integer"/>
	<column name="thread_id" type="Integer"/>
	<behavior name="nested_set">
		<parameter name="left_column" value="left"/>
		<parameter name="level_column" value="level"/>
		<parameter name="right_column" value="right"/>
		<parameter name="scope_column" value="thread_id"/>
		<parameter name="use_scope" value="true"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    left:
      type: Integer
    right:
      type: Integer
    level:
      type: Integer
    thread_id:
      type: Integer
    _propel_behaviors:
      nested_set:
        left_column: left
        level_column: level
        right_column: right
        scope_column: thread_id
        use_scope: true

You can go and see how to do this in few clicks.

Query cache

The query_cache behavior gives a speed boost to Propel queries by caching the transformation of a PHP Query object into reusable SQL code.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="name" type="Varchar"/>
	<behavior name="query_cache">
		<parameter name="backend" value="name"/>
		<parameter name="lifetime" value="600"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    _propel_behaviors:
      query_cache:
        backend: name
        lifetime: 600

You can go and see how to do this in few clicks.

Sluggable

The sluggable behavior allows a model to offer a human readable identifier that can be used for search engine friendly URLs.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="name" type="Varchar" primaryString="true"/>
	<column name="url" type="Varchar"/>
	<behavior name="sluggable">
		<parameter name="slug_column" value="url"/>
		<parameter name="permanent" value="true"/>
		<parameter name="slug_pattern" value="/items/{name}"/>
		<parameter name="replacement" value="-"/>
		<parameter name="separator" value="/"/>
		<parameter name="replace_pattern" value="/[^\w\/]+/u"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    url:
      type: Varchar
    _propel_behaviors:
      sluggable:
        slug_column: url
        permanent: true
        slug_pattern: /items/{name}
        replacement: -
        separator: /
        replace_pattern: /[^\w\/]+/u

You can go and see how to do this in few clicks.

Soft Delete

The soft_delete behavior overrides the deletion methods of a model object to make them ‘hide’ the deleted rows but keep them in the database.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="deleted" type="Timestamp"/>
	<behavior name="soft_delete">
		<parameter name="deleted_column" value="deleted"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    deleted:
      type: Timestamp
    _propel_behaviors:
      soft_delete:
        deleted_column: deleted

You can go and see how to do this in few clicks.

Sortable

The sortable behavior allows a model to become an ordered list, and provides numerous methods to traverse this list in an efficient way.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="rank" type="Integer"/>
	<column name="item_id" type="Integer"/>
	<behavior name="sortable">
		<parameter name="rank_column" value="rank"/>
		<parameter name="scope_column" value="item_id"/>
		<parameter name="use_scope" value="true"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    rank:
      type: Integer
    item_id:
      type: Integer
    _propel_behaviors:

      sortable:
        rank_column: rank
        scope_column: item_id
        use_scope: true

You can go and see how to do this in few clicks.

Timestampable

The timestampable behavior allows you to keep track of the date of creation and last update of your model objects.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="createdAt" type="Timestamp"/>
	<column name="updatedAt" type="Timestamp"/>
	<behavior name="timestampable">
		<parameter name="create_column" value="createdAt"/>
		<parameter name="update_column" value="updatedAt"/>
		<parameter name="disable_updated_at" value="false"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    createdAt:
      type: Timestamp
    updatedAt:
      type: Timestamp
    _propel_behaviors:
      timestampable:
        create_column: createdAt
        update_column: updatedAt
        disable_updated_at: false

You can go and see how to do this in few clicks.

Versionable

The versionable behavior provides versioning capabilities to any ActiveRecord object.

XML
YML
Links
<table name="itemRecord">
	<column name="id" primaryKey="true"/>
	<column name="version" type="Integer"/>
	<behavior name="versionable">
		<parameter name="version_column" value="version"/>
		<parameter name="log_created_at" value="true"/>
		<parameter name="log_created_by" value="true"/>
	</behavior>
</table>
propel:
  itemRecord:
    id:
      type: integer
      primaryKey: true
    name:
      type: Varchar
    version:
      type: Integer
    _propel_behaviors:
      versionable:
        version_column: version
        log_created_at: true
        log_created_by: true

You can go and see how to do this in few clicks.

Skipper

Skipper application



Definitions on this page were modelled and generated by Skipper, visual schema editor for ORM frameworks.

Skipper greatly simplifies work with Propel and saves huge amount of time. Every example entity and relation used in this Cheatsheet can be achieved with just a few clicks with Skipper. Generated code is clean and elegant and complies with all coding standards.

To learn how Skipper works visit the product tour.

Export to Propel definitions

Entity editor

Entity editor

Skipper allows to model and export the definition for every Propel element and its properties. Further advantages of automated export are:

  • Editing and generating of definitions is fully repeatable.
  • Standardized definitions are immediately ready-to-use.
  • All typos and syntax errors are 100% eliminated.

Useful links:
Project export - more info about Skipper definitions export
Export to Propel - how to export your changes to definition schema files

Import of a project

Export dialog

Export dialog

Any existing Propel project can be simply and quickly imported to Skipper. This enables:

  • To visualize logic of any project.
  • To start to use application in any phase of the project.

Useful links:
Project import - general information about import feature
Propel project import - how to import existing project to Skipper

Summary of Skipper benefits

Import dialog

Import dialog

  • Allows to create and maintain the project four times faster.
  • Replaces manual definitions writing and reduces errors.
  • Displays the model schema in a form of interactive enhanced ER diagram.
  • Emphasizes the creative part of a project and eliminates the stereotype.
  • Increases work comfort.
  • Provides quality project documentation.
  • Reduces requirements on knowledge and experience of programmers.
  • Simplifies the cooperation between team members.

Skipper download

Atlantic model

Atlantic model

You can try Skipper during its 14-day evaluation period. Trial version offers full application functionality without any limitation and no credit card is needed.

Download trial version from the tool websites at www.skipper18.com/download.

Download Skipper

See also

Do you know any other helpful or interesting sites that should be linked here?
Let us know: developers@ormcheatsheet.com


Found a typo? Something is wrong or missing in the Cheatsheet? Just fork and edit it!

ORM Cheat Sheet

Created by Inventic developed by community

If you want to leave feedback, contact us developers@ormcheatsheet.com


Fork me on GitHub Real Time Web Analytics