When convention over configuration sucks

Posted by – February 2, 2009

Last saturday I wrote a small application using rails 2.2.2, rails is pretty handy in many ways, when writing models, controllers and views, I could get this application working almost like its jsf version, except for one thing, convention on primary keys.

Rails has a convention on primary keys, if you are using sqlite as database you are limited to use an auto-increment column as primary key, no user provided id is allowed. You can customize the column name of primary key, but nothing more.

To change the column name of your primary key you must call set_primary_key method on your model class, like below:

class Supplier < ActiveRecord::Base
   set_table_name "supplier"
   set_primary_key "fid"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>