Doctrine (within Symfony) Timestampable
For most tables there is usually a need to track when a row was created or updated. Doctrine allows for this type of behavior but in a different way. If your table has created_at and updated_at columns (or just one or the other) you can tell doctrine to automatically set the correct timestamp. The datatype I use for my created_at and updated_at columns are ‘datetime’ so my schema would look like:
... `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL ...
To ensure that your columns are updated you will need to edit your config/doctrine/schemal.yml file and add the following lines:
Before
tableName: objects
columns:
id:
type: integer(4)
primary: true
autoincrement: true
name:
type: string(50)
notnull: true
After
tableName: objects
actAs:
Timestampable:
created:
name: created_at
type: timestamp
updated:
name: updated_at
type: timestamp
columns:
id:
type: integer(4)
primary: true
autoincrement: true
name:
type: string(50)
notnull: true
Now that you edited your schema file you will need to rebuild your model so that the php model files know that you will be updating these columns during saves:
php symfony doctrine:build-model
And as always, clear your cache so that your code will be using the latest version of model files:
php symfony cc
For more information on timestample /w doctrine, visit their website.
This entry was posted by Mike Purcell on October 11, 2009 at 6:38 pm, and is filed under Doctrine, Symfony. Follow any responses to this post through RSS 2.0.You can leave a response or trackback from your own site.
- Symfony – Doctrine – Call to a member function evictAll on a non-object
- Symfony – Standard API for Logging Using __callStatic
- Symfony – Symfony 2 Security Audit Results
- Symfony – Serve External Apis from External Hosts – jQuery – Yui
- Symfony – sfGuardPlugin – Use Email Instead of Username
- Symfony – PHP – Possibly Forking 1.x so Invested Companies don’t Lose Millions
- Symfony – Remove .php From Controller using Symlink
- Symfony – Add ReCaptcha to JQuery Dialog (Lightbox)
- Symfony – Custom (Private) Plugins – Naming Convention
- Symfony – Standard API for Logging

