Sunday, February 04, 2007

Foreign Keys and Views!

In their Beginning Ruby on Rails E-Commerce, Christian Hellsten and Jarkko Laine use MySQL-specific SQL code to add foreign key constraints with cascading deletes to some of the tables defined using the ActiveRecord concepts. Having done so, and in order to enforce these constraints, they resort to incorporating code, in the "view" components of their application for adding objects to the tables. These additions to the already generated views ensure that the new objects posted to the database do not violate the foreign key constraints. I'm really not sure if there are other ways to define such constraints within Rails so that one does not need to use DB-specific SQL which obviously cannot be digested by ActiveRecord database migration tools. If there's no such alternative, I could be tempted to conclude that ActiveRecord has features that are mis-matched to some of the assumptions behind normalization principles of relational algebra. However, I should not be this judgmental yet. I've just begun to learn about Rails.

Tailing a log

To tail a log file during tests of a Rails application, you can try "tail -f logs/test.log". If you do a "rake" of your project, this will show the beginning and rollback of various transactions against the test database.

About Rails

Beginning Ruby on Rails E-Commerce, published by APRESS, provides a decent, practical introduction to Rails programming model, with a very useful example than runs through the book.