ActiveRecord - seriously?

There are some pieces of technology that are so horrible that they quickly become ubiquitous. why is that? PHP, Java, Javascript and MongoDB come readily to mind. Another member of this list is ActiveRecord. That it was developed is not really surprising - that it has gained such widespread popularity is. How come no one has tried to rip apart the beast that is Rails and rip out its putrid heart that is ActiveRecord? Oh, sorry - they did!

A confession - I had never used ActiveRecord until recently. My Ruby life started with Merb, which ships DataMapper as default, and DataMapper is beautiful. some of things that you never need to deal with in DataMapper

  • Your model properties in some other file. Retardedness like ‘schema.rb is the canonical list of columns’….and what if you are using Postgres HStore? you cannot use schema.rb anymore and you set the dump format to sql? Now do I need to wade through raw SQL? Or open an irb prompt and say Model.attributes?Seriously?
  • No Enums? Seriously? Go hunting for any of a hundred enumerated_attribute gems. Most of them will store your Enum as a String in the database? Seriously? Why wouldn’t I just use String then?
  • Validating with custom validators is like - seriously?

    validates_each :user do |record, attr, value|
     record.errors.add attr, " has to be a customer but is #{value.role}" if value and not    ["customer","admin"].include?(value.role)
  • Setting default proprty values merits a StackOverflow post

  • Migrations. Holy Mother of God - what a pain in arse. I understand there are some 0.01% corner cases where you want total control over how the database is migrated but come on - your framework should be smart enough to figure out what the database table should look like. Besides, ActiveRecord migrations are so half-assed, they’re almost a joke - You can say t.references :other_models and it doesn’t even add a foreign key, and to add salt to DRY wounds, you have to go back and specify the relationship in the model?

Why are so many people building complex applications using ActiveRecord? How are they doing it? I could not abide it for more than a week. I really tried. I’ve been lured by the awesome support from the community such as ActiveRecord Postgres HStore support and the super gorgeous ActiveAdmin but seriously - it doesn’t seem worth it.

The big surprise for me was the response to the question - Who has used DataMapper? - at RubyConf India. Only the questioner and myself had (and on the same project no less). Rails people - try DataMapper. It will change your life. And DM2 is going to be even more awesome.

Here’s some links to whet your appetite: