references
Adds a FOREIGN KEY constraint to this column, referencing another column.
This function creates a foreign key relationship between this column (the child) and a column in another table (the parent). It ensures that a value cannot be inserted into this column unless it already exists in the referenced parent column. This enforces referential integrity between tables.
You can also specify actions to be taken when a referenced parent key is updated or deleted.
Example:
object Authors : KQLiteTable("authors") {
val authorId = longColumn("id").primaryKey()
val name = stringColumn("name").notNull()
}
object Books : KQLiteTable("books") {
val bookId = longColumn("id").primaryKey()
val title = stringColumn("title").notNull()
// This column must reference a valid 'authorId' in the 'Authors' table.
// If an author is deleted, all their books will be deleted as well.
val authorFk = longColumn("author_id")
.references(Authors.authorId, onDelete = ForeignKeyAction.CASCADE)
}Return
The same KQLiteColumn instance, now with a foreign key constraint, to allow for further chaining.
Author
MOHAMMAD AZIM ANSARI
Parameters
The parent column that this column references.
The action to perform when the referenced parent key is deleted. Common actions include CASCADE, SET NULL, RESTRICT. See ForeignKeyAction.
The action to perform when the referenced parent key is updated. Common actions include CASCADE, SET NULL, RESTRICT. See ForeignKeyAction.