数据库元被影射成对象
(object-relational mapping (ORM)层)

Ruby代码
  1. table<=>class
  2. row<=>object
  3. column<=>object attribute

class和table的命名对应关系实例:

Ruby代码
  1. Order<=>orders
  2. TaxAgency<=>tax_agencies
  3. Person<=>people

 

Ruby代码
  1. #复数形式关闭方法config/environment.rb:
  2. ActiveRecord::Base.pluralize_table_names = false
  3. #自定义表格名称方法:
  4. class Sheep < ActiveRecord::Base
  5. set_table_name "sheep"
  6. end

Ruyb数据类型和SQL数据类型对应关系表:

Ruby代码
    1. int,integer<=>Fixnum
    2. float,double,decimal,numeric<=>Float
    3. interval,date<=>Date
    4. datetime,time<=>Time
    5. char,varchar,string,clob,blob,text<=>String
    6. boolean<=>see text...

%3