English | 简体中文

api-docs / org.ktorm.schema / Table / references

references

inline fun <C : Any, R : Entity<R>> Column<C>.references(
    referenceTable: Table<R>,
    selector: (E) -> R?
): Column<C>
(source code)

Bind the column to a reference table, equivalent to a foreign key in relational databases.
Entity sequence APIs would automatically left-join all references (recursively) by default.

Note: Since Column is immutable, this function will create a new Column instance and replace
the origin registered one.

Parameters

referenceTable - the reference table, will be copied by calling its aliased function with
an alias like _refN.

selector - a lambda in which we should return the property used to hold the referenced entities.
For example: val departmentId = int("department_id").references(Departments) { it.department }.

Return
the new Column instance.

See Also

org.ktorm.entity.sequenceOf

createEntity