Active Record 連線配接器 表格
以抽象的方式表示 SQL 表格,用於更新表格。另請參閱 TableDefinition
和 connection.create_table
可用的轉換為
change_table :table do |t|
t.primary_key
t.column
t.index
t.rename_index
t.timestamps
t.change
t.change_default
t.change_null
t.rename
t.references
t.belongs_to
t.check_constraint
t.string
t.text
t.integer
t.bigint
t.float
t.decimal
t.numeric
t.datetime
t.timestamp
t.time
t.date
t.binary
t.blob
t.boolean
t.foreign_key
t.json
t.virtual
t.remove
t.remove_foreign_key
t.remove_references
t.remove_belongs_to
t.remove_index
t.remove_check_constraint
t.remove_timestamps
end
- B
- C
- F
- I
- N
- R
- T
屬性
[R] | name |
類別公開方法
new(table_name, base) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 716 def initialize(table_name, base) @name = table_name @base = base end
實例公開方法
change(column_name, type, **options) 連結
根據新的選項更改欄位的定義。
t.change(:name, :string, limit: 80)
t.change(:description, :text)
有關您可以使用的選項的詳細資訊,請參閱 TableDefinition#column
。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 793 def change(column_name, type, **options) raise_on_if_exist_options(options) @base.change_column(name, column_name, type, **options) end
change_default(column_name, default_or_changes) 連結
設定欄位的新預設值。
t.change_default(:qualification, 'new')
t.change_default(:authorized, 1)
t.change_default(:status, from: nil, to: "draft")
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 805 def change_default(column_name, default_or_changes) @base.change_column_default(name, column_name, default_or_changes) end
change_null(column_name, null, default = nil) 連結
設定或移除欄位上的 NOT NULL 條件約束。
t.change_null(:qualification, true)
t.change_null(:qualification, false, 0)
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 815 def change_null(column_name, null, default = nil) @base.change_column_null(name, column_name, null, default) end
check_constraint(*args, **options) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 925 def check_constraint(*args, **options) @base.add_check_constraint(name, *args, **options) end
check_constraint_exists?(*args, **options) 連結
檢查表格上是否存在 check_constraint
。
unless t.check_constraint_exists?(name: "price_check")
t.check_constraint("price > 0", name: "price_check")
end
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 945 def check_constraint_exists?(*args, **options) @base.check_constraint_exists?(name, *args, **options) end
column(column_name, type, index: nil, **options) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 726 def column(column_name, type, index: nil, **options) raise_on_if_exist_options(options) @base.add_column(name, column_name, type, **options) if index index_options = index.is_a?(Hash) ? index : {} index(column_name, **index_options) end end
column_exists?(column_name, type = nil, **options) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 740 def column_exists?(column_name, type = nil, **options) @base.column_exists?(name, column_name, type, **options) end
foreign_key(*args, **options) 連結
使用提供的表格名稱將外部鍵新增至表格。
t.foreign_key(:authors)
t.foreign_key(:authors, column: :author_id, primary_key: "id")
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 895 def foreign_key(*args, **options) raise_on_if_exist_options(options) @base.add_foreign_key(name, *args, **options) end
foreign_key_exists?(*args, **options) 連結
檢查外部鍵是否存在。
t.foreign_key(:authors) unless t.foreign_key_exists?(:authors)
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 916 def foreign_key_exists?(*args, **options) @base.foreign_key_exists?(name, *args, **options) end
index(column_name, **options) 連結
將新索引新增至表格。 column_name
可以是單個 Symbol
或 Array
的 Symbols。
t.index(:name)
t.index([:branch_id, :party_id], unique: true)
t.index([:branch_id, :party_id], unique: true, name: 'by_branch_party')
有關您可以使用的選項的詳細資訊,請參閱 connection.add_index。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 752 def index(column_name, **options) raise_on_if_exist_options(options) @base.add_index(name, column_name, **options) end
index_exists?(column_name, **options) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 764 def index_exists?(column_name, **options) @base.index_exists?(name, column_name, **options) end
references(*args, **options) 連結
新增參考。
t.references(:user)
t.belongs_to(:supplier, foreign_key: true)
有關您可以使用的選項的詳細資訊,請參閱 connection.add_reference。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 867 def references(*args, **options) raise_on_if_exist_options(options) args.each do |ref_name| @base.add_reference(name, ref_name, **options) end end
remove(*column_names, **options) 連結
從表格定義中移除欄位。
t.remove(:qualification)
t.remove(:qualification, :experience)
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 825 def remove(*column_names, **options) raise_on_if_exist_options(options) @base.remove_columns(name, *column_names, **options) end
remove_check_constraint(*args, **options) 連結
從表格中移除指定的檢查條件約束。
t.remove_check_constraint(name: "price_check")
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 934 def remove_check_constraint(*args, **options) @base.remove_check_constraint(name, *args, **options) end
remove_foreign_key(*args, **options) 連結
從表格中移除指定的外部鍵。
t.remove_foreign_key(:authors)
t.remove_foreign_key(column: :author_id)
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 906 def remove_foreign_key(*args, **options) raise_on_if_exist_options(options) @base.remove_foreign_key(name, *args, **options) end
remove_index(column_name = nil, **options) 連結
從表格中移除指定的索引。
t.remove_index(:branch_id)
t.remove_index(column: [:branch_id, :party_id])
t.remove_index(name: :by_branch_party)
t.remove_index(:branch_id, name: :by_branch_party)
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 838 def remove_index(column_name = nil, **options) raise_on_if_exist_options(options) @base.remove_index(name, column_name, **options) end
remove_references(*args, **options) 連結
移除參考。選擇性地移除 type
欄位。
t.remove_references(:user)
t.remove_belongs_to(:supplier, polymorphic: true)
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 881 def remove_references(*args, **options) raise_on_if_exist_options(options) args.each do |ref_name| @base.remove_reference(name, ref_name, **options) end end
remove_timestamps(**options) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 848 def remove_timestamps(**options) @base.remove_timestamps(name, **options) end
rename(column_name, new_column_name) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 857 def rename(column_name, new_column_name) @base.rename_column(name, column_name, new_column_name) end
rename_index(index_name, new_index_name) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 773 def rename_index(index_name, new_index_name) @base.rename_index(name, index_name, new_index_name) end
timestamps(**options) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 782 def timestamps(**options) raise_on_if_exist_options(options) @base.add_timestamps(name, **options) end