rails icon

ActiveRecord - Achilles Heel of Ruby on Rails?

Posted in , , Sun, 04 Jun 2006 16:12:00 GMT

IMO, one of the major limitations of Ruby on Rails compared to other frameworks is its ORM, ActiveRecord. ActiveRecord is a fairly early ORM (object-relational mapper) that has made some questionable design decisions and doesn't support some very basic relational database concepts. These issues have been discussed on Joel on Software and elsewhere. Here are some limitations I wish were fixed:

  1. No Foreign Key Support: Although RoR lets you define has_many relationships, it makes no effort to create foreign key constraints in the underlying database to ensure relational integrity.
  2. No Multi-column Primary Key Support: Multi-column primary keys are a staple of relational database schema definition. Unfortunately, DDH had a pretty simple response:

    > Is there a way to set an ActiveRecord object to point to a table
    > with a multi-column primary key?

    Not really, no. Active Record was designed for a single column primary key and that assumption runs pretty deep. AR is not a Data Mapper, so you have to be within a reasonable vicinity of its assumptions to enjoy it.
    - David Heinemeier Hansson

As DHH says in his multi-col PK response, you need to be close to ActiveRecord's assumptions, it doesn't cater to your situation. ActiveRecord is nice for many simpler situations but if you want relational integrity and/or have complex relationships, it seems like it may not be the best tool for the job. Other ORMs such as the Perl-based DBIx::Class (often used with the Catalyst framework) can handle these issues and many more. According to the 37Signals blog entry Growing in vs. growing out, they prefer people to grow out of their applications. I'm curious if they also want people to grow out of ActiveRecord?

del.icio.us:ActiveRecord - Achilles Heel of Ruby on Rails? digg:ActiveRecord - Achilles Heel of Ruby on Rails? reddit:ActiveRecord - Achilles Heel of Ruby on Rails? spurl:ActiveRecord - Achilles Heel of Ruby on Rails? wists:ActiveRecord - Achilles Heel of Ruby on Rails? simpy:ActiveRecord - Achilles Heel of Ruby on Rails? newsvine:ActiveRecord - Achilles Heel of Ruby on Rails? blinklist:ActiveRecord - Achilles Heel of Ruby on Rails? furl:ActiveRecord - Achilles Heel of Ruby on Rails? fark:ActiveRecord - Achilles Heel of Ruby on Rails? blogmarks:ActiveRecord - Achilles Heel of Ruby on Rails? Y!:ActiveRecord - Achilles Heel of Ruby on Rails? smarking:ActiveRecord - Achilles Heel of Ruby on Rails? magnolia:ActiveRecord - Achilles Heel of Ruby on Rails? segnalo:ActiveRecord - Achilles Heel of Ruby on Rails?

3 comments

Comments

  1. Jack Hung said 2 months later:

    ActiveRecord composite primary keys extension available from Dr Nic Williams:

    http://compositekeys.rubyforge.org/

  2. John Wang said 2 months later:

    Thanks for posting. That looks very interesting. I hope composite PK support will get integrated into ActiveRecord proper since this is core functionality that I’d rely on, not some add-on feature that I could just turn off in the event of future incompatibilities or other issues.

  3. Prince Singh said about 1 year later:

    ActiveScaffold does not work with Composite keys plugin mentioned above

(leave url/email »)

   Comment Markup Help Preview comment