diff --git a/src/main/kotlin/org/jetbrains/exposed/dao/Entity.kt b/src/main/kotlin/org/jetbrains/exposed/dao/Entity.kt index f4c16413c5..9a1b65d795 100644 --- a/src/main/kotlin/org/jetbrains/exposed/dao/Entity.kt +++ b/src/main/kotlin/org/jetbrains/exposed/dao/Entity.kt @@ -8,6 +8,7 @@ import java.util.* import java.util.concurrent.ConcurrentHashMap import kotlin.properties.Delegates import kotlin.properties.ReadOnlyProperty +import kotlin.properties.ReadWriteProperty import kotlin.reflect.KClass import kotlin.reflect.KProperty import kotlin.reflect.full.primaryConstructor @@ -126,18 +127,18 @@ class View> (val op : Op, val factory: EntityClas } @Suppress("UNCHECKED_CAST") -class InnerTableLink, Target: Entity>(val table: Table, - val target: EntityClass) { - private fun getSourceRefColumn(o: Entity<*>): Column> { - val sourceRefColumn = table.columns.singleOrNull { it.referee == o.klass.table.id } as? Column> ?: error("Table does not reference source") - return sourceRefColumn +class InnerTableLink, ID:Comparable, Target: Entity>(val table: Table, + val target: EntityClass) : ReadWriteProperty> { + + private fun getSourceRefColumn(o: Source): Column> { + return table.columns.singleOrNull { it.referee == o.klass.table.id } as? Column> ?: error("Table does not reference source") } private fun getTargetRefColumn(): Column> { return table.columns.singleOrNull { it.referee == target.table.id } as? Column> ?: error("Table does not reference target") } - operator fun getValue(o: Entity<*>, desc: KProperty<*>): SizedIterable { + override operator fun getValue(o: Source, unused: KProperty<*>): SizedIterable { if (o.id._value == null) return emptySized() val sourceRefColumn = getSourceRefColumn(o) val alreadyInJoin = (target.dependsOnTables as? Join)?.alreadyInJoin(table)?: false @@ -150,13 +151,13 @@ class InnerTableLink, Target: Entity>(val table: Table, return TransactionManager.current().entityCache.getOrPutReferrers(o.id, sourceRefColumn, query) } - operator fun> setValue(o: Entity, desc: KProperty<*>, value: SizedIterable) { +override fun setValue(o: Source, unused: KProperty<*>, value: SizedIterable) { val sourceRefColumn = getSourceRefColumn(o) val targetRefColumn = getTargetRefColumn() val entityCache = TransactionManager.current().entityCache entityCache.flush() - val oldValue = getValue(o, desc) + val oldValue = getValue(o, unused) val existingIds = oldValue.map { it.id }.toSet() entityCache.clearReferrersCache() @@ -283,7 +284,7 @@ open class Entity>(val id: EntityID) { column.setValue(o, desc, toColumn(value)) } - infix fun , Target:Entity> EntityClass.via(table: Table): InnerTableLink = + infix fun , Target:Entity> EntityClass.via(table: Table): InnerTableLink, TID, Target> = InnerTableLink(table, this@via) fun > s(c: EntityClass<*, T>): EntityClass<*, T> = c