Tuesday, 2 November 2010

Don't forget your relational database

Now the good old relational database has had a bit of a bad wrap lately. It's all about document databases and flat tables and CQRS and blah, blah, blah. Well let me just remind you that most of us are still 'dealing' with our friend mr relational database and I'd like us all to take a moment to treat him with the respect he deserves... or at least not forget that he still exists and requires a little bit of relationship management.

On my current project we're using an ORM to map our database objects to the nice (ahem) OO one's we've created. For our ORM we're using NHibernate and Active Record (to remove the xml configuration layer). However it has come to my attention recently that many developers were under the impression that adding attributes of HasMany and BelongsTo to the OO object properties you map to your database would carry that relational constraint down the the database. But I'm afraid not folks! That dependency still needs adding to your database the old fashioned way using your migrations. If you forget to push this constraint down you are in danger of some other code somewhere else in your system or worse outside of your system breaking the relational integrity of your database....boom!

I openly admit that this is a pain and probably another plus point for relational database naysayers but as I said earlier we still have to be nice to mr relational so don't forget him please :)