Accessor

class Accessor<ID : Any, Parent : Entity<ID>, REF : Any>(reference: Column<REF>, factory: EntityClass<ID, Parent>, entity: Entity<*>, references: Map<Column<*>, Column<*>>? = null)

What a non-nullable many-to-one reference declared with referencedOn gives back. Declare the property as a val, read the referenced entity by invoking it, and write it with set:

class Film(id: EntityID<Int>) : IntEntity(id) {
val director by Director referencedOn Films.director

companion object : IntEntityClass<Film>(Films)
}

val name = film.director().name // suspends, and queries unless the entity is already cached
film.director.set(otherDirector) // does not suspend: staged like any other column write

The property hands back this accessor rather than the entity itself because reading it has to suspend and a property getter cannot — the JDBC DAO, where the read blocks, returns the entity directly.

Constructors

Link copied to clipboard
constructor(reference: Column<REF>, factory: EntityClass<ID, Parent>, entity: Entity<*>, references: Map<Column<*>, Column<*>>? = null)

Functions

Link copied to clipboard
operator fun getValue(thisRef: Any?, property: KProperty<*>): Accessor<ID, Parent, REF>

Property delegate operator — returns this accessor itself, used to expose invoke / set.

Link copied to clipboard
suspend operator fun invoke(): Parent

Suspending read of the referenced parent entity. Looks up the entity from the cache, or otherwise resolves the parent by querying the database via factory.

Link copied to clipboard
fun set(value: Parent)

Writes the link to value into the underlying reference column(s) and pins it in the entity's reference cache.