class CQL::ForeignKey

Overview

A foreign key constraint This class represents a foreign key constraint It provides methods for setting the columns, table, and references It also provides methods for setting the on delete and on update actions

Example Creating a new foreign key

Schema.define do
  table :users do
    column :id, Int32, primary: true
    column :name, String
  end
end

table :posts do
  column :id, Int32, primary: true
  column :user_id, Int32
  foreign_key [:user_id], :users, [:id]
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]