Posts Tagged Doctrine

actAs: Accountable Doctrine Behaviour

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.

, , , , ,

No Comments

Doctrine Behaviours

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.

, , , ,

No Comments

Database Schema and Doctrine Model planning

Today I did some major database planning for a major project I’m working on and it’s quite an interesting process. You have to take such a large concept as every bit of information your application might need to store and slicing that into smaller pieces to create the tables and models needed to access and process them.

I’m finding the best way to plan them out is to grab a piece of paper and something to write with and start scribbling.  Maybe it is low tech but whatever works you know.  I found myself creating what could have easily have been a flow chart spanning several pages. I started in one small area and quickly expanded to other less obvious and obscure tables I’d need. All while relaxing on my bed.

I started writing my schema file. This being my first real application of the Doctrine ORM it was a bit slow going. The syntax for the schema.yml is a bit new to me. It took me a couple tries to get the correct relationships to form exactly the way I wanted. But so far so good.

, , , , ,

No Comments