跳至内容 跳至搜索
方法
C
P

实例公共方法

column(name, type, **options)

追加指定类型的列或列。

t.string(:goat)
t.string(:goat, :sheep)

TableDefinition#column

# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 319
included do
  define_column_methods :bigint, :binary, :boolean, :date, :datetime, :decimal,
    :float, :integer, :json, :string, :text, :time, :timestamp, :virtual

  alias :blob :binary
  alias :numeric :decimal
end

primary_key(name, type = :primary_key, **options)

将主键定义追加到表定义。可以多次调用,但这不是一个好主意。

# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 304
def primary_key(name, type = :primary_key, **options)
  column(name, type, **options.merge(primary_key: true))
end