reference

fun <T : Any> reference(name: String, refColumn: Column<T>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<T>

Creates a column with the specified name with a reference to the refColumn column and with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

Parameters

name

Name of the column.

refColumn

A column from another table which will be used as a "parent".

onDelete

Optional ReferenceOption for cases when a linked row from a parent table will be deleted.

onUpdate

Optional ReferenceOption for cases when a value in a referenced column will be changed.

fkName

Optional foreign key constraint name.

Samples

org.jetbrains.exposed.sql.tests.shared.entities.EntityTests.Orders
@JvmName(name = "referenceByIdColumn")
fun <T : Any, E : EntityID<T>> reference(name: String, refColumn: Column<E>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<E>

Creates a column with the specified name with a reference to the refColumn column and with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

Parameters

name

Name of the column.

refColumn

A column from another table which will be used as a "parent".

onDelete

Optional ReferenceOption for cases when a linked row from a parent table will be deleted.

onUpdate

Optional ReferenceOption for cases when a value in a referenced column will be changed.

fkName

Optional foreign key constraint name.

Samples

org.jetbrains.exposed.sql.tests.shared.entities.EntityTests.Schools
fun <T : Any> reference(name: String, foreign: IdTable<T>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<EntityID<T>>

Creates a column with the specified name with a reference to the id column in foreign table and with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

Parameters

name

Name of the column.

foreign

A table with an id column which will be used as a "parent".

onDelete

Optional ReferenceOption for cases when a linked row from a parent table will be deleted.

onUpdate

Optional ReferenceOption for cases when a value in a referenced column will be changed.

fkName

Optional foreign key constraint name.

Samples

org.jetbrains.exposed.sql.tests.shared.entities.EntityTests.Schools