跳至内容 跳至搜索

Active Record PostgreSQL 适配器表

方法
E
R
U
V
包含模块

实例公共方法

exclusion_constraint(*args)

添加排他约束。

t.exclusion_constraint("price WITH =, availability_range WITH &&", using: :gist, name: "price_check")

connection.add_exclusion_constraint

# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 309
def exclusion_constraint(*args)
  @base.add_exclusion_constraint(name, *args)
end

remove_exclusion_constraint(*args)

从表中删除给定的排他约束。

t.remove_exclusion_constraint(name: "price_check")

connection.remove_exclusion_constraint

# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 318
def remove_exclusion_constraint(*args)
  @base.remove_exclusion_constraint(name, *args)
end

remove_unique_constraint(*args)

从表中删除给定的唯一约束。

t.remove_unique_constraint(name: "unique_position")

connection.remove_unique_constraint

# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 336
def remove_unique_constraint(*args)
  @base.remove_unique_constraint(name, *args)
end

unique_constraint(*args)

添加唯一约束。

t.unique_constraint(:position, name: 'unique_position', deferrable: :deferred, nulls_not_distinct: true)

connection.add_unique_constraint

# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 327
def unique_constraint(*args)
  @base.add_unique_constraint(name, *args)
end

validate_check_constraint(*args)

验证表上的给定检查约束。

t.check_constraint("price > 0", name: "price_check", validate: false)
t.validate_check_constraint name: "price_check"

connection.validate_check_constraint

# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 356
def validate_check_constraint(*args)
  @base.validate_check_constraint(name, *args)
end

validate_constraint(*args)

验证表上的给定约束。

t.check_constraint("price > 0", name: "price_check", validate: false)
t.validate_constraint "price_check"

connection.validate_constraint

# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 346
def validate_constraint(*args)
  @base.validate_constraint(name, *args)
end