Let's say we have an "Organization" table. The "Organization" has a foreign key pointing to another "Organization" row within the same table as its parent. In Jetbrains Exposed, the one-to-one self-referencing relationship can be declared as:
object OrganizationTable : IntIdTable () {
val name = varchar("name", 256)
.
.
.
val parent = reference("parent", OrganizationTable, ReferenceOption.RESTRICT).nullable()
}
How do I do the same to the counterpart DAO entity declaration? I got errors using the following declaration:
class OrganizationEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<OrganizationEntity>(OrganizationTable)
var name by OrganizationTable.name
.
.
.
var parent by ? ? ? ? ? ? // error using: by OrganizationEntity referencedOn OrganizationTable.parent
}
Thanks in advance!