Adding custom information to your Doctrine schema

Sometime ago I needed to add some custom information to each of my Doctrine 1 tables in a schema. It was for  an interesting and time saving functionality I will describe in a future post. For now I’m going to describe how to add and then retrieve custom data to each schema model.

First let’s see an example schema:

 
Post:
  tableName:  post
  columns:
    id:       { type: integer  , length: 20 , primary: true    , autoincrement: true }
    title:    { type: string   , length: 200                   , notnull: true       }
    content:  { type: string   , length: 20000                 , notnull: true       }
  options:
    symfony:  { filter: false, form: true }
 

Now suppose you wanna add some parameter to our post table that indicates this is a special table. Let’s see how to do this:

 
Post:
  tableName:  post
  columns:
    id:       { type: integer  , length: 20 , primary: true    , autoincrement: true }
    title:    { type: string   , length: 200                   , notnull: true       }
    content:  { type: string   , length: 20000                 , notnull: true       }
  options:
    symfony:  { filter: false, form: true }
    special:  'this is my special table'
 

Now if you wanna retrieve this data:

 
  public function executeIndex(sfWebRequest $request)
  {
    $this->special = Doctrine::getTable('Post')->getOption('special'));
  }
 

Then, in the template the special var will contain:

 
  this is my special table
 

This way you can indicate custom data on a table basis.

You can find a lot of uses for this special functionality, and if you don’t I will show one on an upcoming post.

Leave a Reply

Your email address will not be published. Required fields are marked *