OptionalAccessor

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

What a nullable many-to-one reference declared with optionalReferencedOn gives back. Same val + invoke()/set shape as Accessor, except that both ends accept null:

class Film(id: EntityID<Int>) : IntEntity(id) {
val producer by Producer optionalReferencedOn Films.producer

companion object : IntEntityClass<Film>(Films)
}

val name = film.producer()?.name
film.producer.set(null) // clears the reference

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<*>): OptionalAccessor<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 optionally referenced parent entity. Returns null when the underlying reference column(s) are unset.

Link copied to clipboard
fun set(value: Parent?)

Writes the link to value (or clears it when null) into the underlying reference column(s).