class CQL::ForeignKey

Overview

A foreign key constraint: the local columns, the referenced table and columns, and the ON DELETE / ON UPDATE actions. Declare one with Table#foreign_key in a table block, or add one later with AlterTable#foreign_key.

Example Declaring a foreign key

schema.table :comments do
  primary :id, Int64
  column :post_id, Int64
  foreign_key [:post_id], references: :posts, references_columns: [:id], on_delete: :cascade
end

Defined in:

foreign_key.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(table : CQL::Table, columns : Array(Symbol), references_table : Symbol, references_columns : Array(Symbol), name : String | Nil = nil, on_delete : Symbol = :no_action, on_update : Symbol = :no_action) #

[View source]

Instance Method Detail

def columns : Array(Symbol) #

The column(s) in the current table that make up the foreign key.


[View source]
def name : String | Nil #

Name of the foreign key constraint (optional, often auto-generated).


[View source]
def on_delete : Symbol #

Action to perform on delete (e.g., :cascade, :restrict, :set_null, :no_action).


[View source]
def on_update : Symbol #

Action to perform on update (e.g., :cascade, :restrict, :set_null, :no_action).


[View source]
def references_columns : Array(Symbol) #

The column(s) in the referenced table.


[View source]
def references_table : Symbol #

The table that the foreign key references.


[View source]
def table : CQL::Table #

The table this foreign key constraint belongs to.


[View source]