Sword 1.0b5 · A simple and friendly weblogging tool for academic environments created by Fingertips design & development.

 
 
 
 
 

Shifting design perspective

TrackBack link: http://blog.markjuh.net/markjuh/trackback/2005/4/7/shifting_design_perspective

Published on 7 April 2005 at 23:23.

Today I got home around 13:00 after having a hard time with the trains yesterday and today.

So, after lunch, I started working on the prototype of the blogging application, which is what I’ve mostly been busy with since Tuesday.

Tuesday I mostly learned how to deal with database design in combination with Rails and how to use the console script to test your models. My first idea was to define my foreign keys as NOT NULL, but this gives the key a default value of 0. In it’s own not much of a problem. I thought that validates_presence_of and validates_associated would take care of this and not accept non-existant foreign key values. But that wasn’t quite right.
So then my idea was to enforce the foreign key constraint directly in the database. But this made sure I could never get my unit tests to work again, since you cannot independently test one of the tables of the one-to-many relationship. Back to the old idea then. But now defined my foreign keys as NULL and giving them a default value of NULL. This at least makes validates_presence_of work and you have to actually change the value of the foreign key to be able to save a record.

But setting a default value of NULL is ugly, right? Sure, if you are looking at it from the old RDBMS-view, that’s absolutely right. But we are now looking at it from the Rails side, which is quite innovative. I had a hard time grasping this too at first, but after a day of discussing it, I remembered an article by Date I had read a couple of years ago in which he argued (quite well I must say) that a RDBMS combined with business logic is in itself again a RDBMS. So when you look at Rails, you have to see for example MySQL + ActiveRecord + models as the RDBMS. And when you take that perspective, it all makes sense. It’s not MySQL anymore that does the constraints, it’s actually defined in the models, so you can use the DRY (Don’t Repeat Yourself) way of working.

Then Wednesday, I’ve mostly been busy with giving functional tests a try and working on the controller and view part of adding a new post to the blog.

Which brings me to the work of today. Mostly been working at some functional tests, getting some green lights and finally some refactoring (mostly of views). I really like working TDD-style, but it annoys me that it’s so hard to write functional tests.

Tomorrow I want to work out comments, logins and creation of new blogs (which requires some database remodeling). So that will mostly be “yay for refactoring”-day.

New comments are disabled for this post