Charmed columns

Posted by tom March 15th, 2006

RAILS/Ruby well, actually ActiveRecord maintains a number of magical column names. These are automatically updated by ActiveRecord and have some nice side effects.

The created_at, created_on, updated_at, updated_on columns are automatically updated with a date/timestamp (_at form) or date (_on form) of a row’s creation or last update.

lock_version is used with optimistic locking. If you use this column name, ActiveRecord will automatically use and check it when updating records.

type is used by single table inheritance for the type of a row (also for class inheritance)

id is the default name of the primary key.

xxx_id is used foreign key references

xxx_count is used counter cache for the child table xxx

position is used for row positioning when you use act_as_list

parent_id is used for row’s parents if you use act_as_tree

Leave a Reply