Back to Exposed

optionalReferrersOn

docs/api/exposed-dao/org.jetbrains.exposed.v1.dao/-entity-class/optional-referrers-on.html

1.2.05.8 KB
Original Source

optionalReferrersOn

infix fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.optionalReferrersOn(column: Column<REF?>): Referrers<ID, Entity<ID>, TargetID, Target, REF?>

Registers an optional reference as an immutable field of the parent entity class, which returns a collection of child objects of this EntityClass that all reference the parent.

The reference should have been defined by the creation of a column using either optReference() or reference().nullable()` on the child table.

By default, this also stores the loaded entities to a cache.

Samples

org.jetbrains.exposed.v1.tests.shared.entities.EntityTests.Categoryorg.jetbrains.exposed.v1.tests.shared.entities.EntityTests.Postsorg.jetbrains.exposed.v1.tests.shared.entities.EntityTests.Post


infix fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.optionalReferrersOn(table: IdTable<*>): Referrers<ID, Entity<ID>, TargetID, Target, Any?>

Registers an optional reference as an immutable field of the parent entity class, which returns a collection of child objects of this EntityClass that all reference the parent.

The reference should have been defined by the creation of a foreign key constraint on the child table, by using foreignKey().

By default, this also stores the loaded entities to a cache.

Samples

org.jetbrains.exposed.v1.tests.shared.entities.CompositeIdTableEntityTest.Publisherorg.jetbrains.exposed.v1.tests.shared.entities.CompositeIdTableEntityTest.Authorsorg.jetbrains.exposed.v1.tests.shared.entities.CompositeIdTableEntityTest.Author


fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.optionalReferrersOn(column: Column<REF?>, cache: Boolean = false): Referrers<ID, Entity<ID>, TargetID, Target, REF?>

Registers an optional reference as an immutable field of the parent entity class, which returns a collection of child objects of this EntityClass that all reference the parent.

The reference should have been defined by the creation of a column using either optReference() or reference().nullable() on the child table.

Set cache to true to also store the loaded entities to a cache.

Samples

org.jetbrains.exposed.v1.tests.shared.entities.EntityTests.Studentorg.jetbrains.exposed.v1.tests.shared.entities.EntityTests.Detentionsorg.jetbrains.exposed.v1.tests.shared.entities.EntityTests.Detention


fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.optionalReferrersOn(table: IdTable<*>, cache: Boolean = false): Referrers<ID, Entity<ID>, TargetID, Target, Any?>

Registers an optional reference as an immutable field of the parent entity class, which returns a collection of child objects of this EntityClass that all reference the parent.

The reference should have been defined by the creation of a foreign key constraint on the child table, by using foreignKey().

Set cache to true to also store the loaded entities to a cache.

Generated by Dokka © 2026 Copyright