Francis's Octopress Blog

A blogging framework for hackers.

Rails里的Magic Column Names

Rails里的Magic Column Names

Active Record有一些富有“魔力”的列名:

created_at, created_on, updated_at, updated_on 在create或者update一行时Rails对at形式的列用timestamp自动更新,对on形式的列用date自动更新

lock_version 如果一个表有lock_version这个列,则Rails会跟踪一行的版本号并执行乐观锁

type 单表继承时跟踪一行的type

id 表的默认主键名

xxx_id 对以复数形式的xxx命名的表的引用的默认外键名

xxx_count 对子表xxx维护一个计数器cache

position acts_as_list时用来表示一个list中该行的position

parent_id acts_as_tree时用来表示该行的parent的id