Posts Tagged behaviours
actAs: Accountable Doctrine Behaviour
Posted by PhazeonPhoenix in Symfony on June 8th, 2009
It was fairly easy to create a Signable behaviour and it was done within a couple days. I soon realized though that the behavior of the SoftDelete behaviour wasn’t quite what I wanted. It only adds a “deleted” boolean field to the DB. I also wanted to know who deleted it and what time it was deleted. I decided to expand SoftDelete and make it use a timestamp instead of a boolean. That part worked too.
The problem I soon ran into was with when I combined SoftDelete and Signable with it’s new preDelete hook. Seems since SoftDelete stops the preDelete event it doesn’t let the Signable code execute properly. I decided that the correct answer to the problem was to create a whole new behaviour which would combine not only SoftDelete and Signable but also Timestampable. I called it Accountable since it’s primary function is to keep record of who touched an object.
I did a manual test and so far it’s worked as planned. I’m not yet sure of the SoftDelete filters… I made a change to preDqlDelete and preDqlSelect and I’m not quite sure if it still works. Time will tell I’m sure. Once I’m more certain this code is solid I’ll give more information on it.
Doctrine Behaviours
Posted by PhazeonPhoenix in Symfony on June 6th, 2009
I’m finding that I need to write a couple behaviors that for some reason are not in the default distribution. The features I’m needing in particular are “Signable” to add created_by, updated_by and deleted_by to each table, and “Commentable” to handle the comments that you’re going to be able to post on almost every single object.
Thankfully the best way for me to learn is to find an example. I’m going to modify the code for “Timestampable” for “Signable” and I think I’m going to look at csDoctrineActAsAttachablePlugin for how it behaves and build from it to make “Commentable”. I might even release it to the community.
Doctrine Behaviours are fairly new to me but I understand what’s going on for sure. Behaviours allow you to modularize your reusable database code. In my examples, I need to be able to keep track of who created, updated, and/or deleted an item. Instead of adding that bit of code to each model by hand, I can cut it out and make a Behaviour that I then attach to each model.
