Skip to content

Commit e497fb8

Browse files
bug fixed
1 parent d6baeb8 commit e497fb8

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

ktorm-core/src/main/kotlin/me/liuwj/ktorm/entity/EntityDml.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ private fun EntityImplementation.findChangedColumns(fromTable: Table<*>): Map<Co
112112
var curr: Any? = this
113113

114114
for ((i, prop) in binding.withIndex()) {
115+
if (curr is Entity<*>) {
116+
curr = curr.implementation
117+
}
118+
115119
check(curr is EntityImplementation?)
116120

117121
val changed = if (curr == null) false else prop.name in curr.changedProperties
@@ -126,11 +130,7 @@ private fun EntityImplementation.findChangedColumns(fromTable: Table<*>): Map<Co
126130
}
127131

128132
anyChanged = anyChanged || changed
129-
130133
curr = curr?.getProperty(prop.name)
131-
if (curr is Entity<*>) {
132-
curr = curr.implementation
133-
}
134134
}
135135

136136
if (anyChanged) {
@@ -169,14 +169,13 @@ internal fun EntityImplementation.doDiscardChanges() {
169169
if (curr == null) {
170170
break
171171
}
172+
if (curr is Entity<*>) {
173+
curr = curr.implementation
174+
}
172175

173176
check(curr is EntityImplementation)
174177
curr.changedProperties.remove(prop.name)
175-
176178
curr = curr.getProperty(prop.name)
177-
if (curr is Entity<*>) {
178-
curr = curr.implementation
179-
}
180179
}
181180
}
182181
}

ktorm-core/src/main/kotlin/me/liuwj/ktorm/entity/EntityExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal fun EntityImplementation.setColumnValue(column: Column<*>, value: Any?)
5454
if (i != binding.lastIndex) {
5555
var child = curr.getProperty(prop.name) as Entity<*>?
5656
if (child == null) {
57-
child = Entity.create(prop.returnType.classifier as KClass<*>, parent = curr, fromTable = column.table)
57+
child = Entity.create(prop.returnType.classifier as KClass<*>, parent = curr)
5858
curr.setProperty(prop.name, child)
5959
}
6060

@@ -91,7 +91,7 @@ internal fun EntityImplementation.forceSetColumnValue(column: Column<*>, value:
9191
if (i != binding.lastIndex) {
9292
var child = curr.getProperty(prop.name) as Entity<*>?
9393
if (child == null) {
94-
child = Entity.create(prop.returnType.classifier as KClass<*>, parent = curr, fromTable = column.table)
94+
child = Entity.create(prop.returnType.classifier as KClass<*>, parent = curr)
9595
curr.setProperty(prop.name, child, forceSet = true)
9696
}
9797

ktorm-core/src/main/kotlin/me/liuwj/ktorm/entity/EntityFinding.kt

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package me.liuwj.ktorm.entity
22

33
import me.liuwj.ktorm.dsl.*
4-
import me.liuwj.ktorm.expression.*
4+
import me.liuwj.ktorm.expression.BinaryExpression
5+
import me.liuwj.ktorm.expression.BinaryExpressionType
6+
import me.liuwj.ktorm.expression.QuerySourceExpression
7+
import me.liuwj.ktorm.expression.ScalarExpression
58
import me.liuwj.ktorm.schema.*
6-
import kotlin.reflect.KClass
79

810
/**
911
* 根据 ID 批量获取实体对象,会自动 left join 所有的引用表
@@ -145,22 +147,8 @@ private fun QueryRowSet.retrieveColumn(column: Column<*>, intoEntity: Entity<*>)
145147
}
146148
is NestedBinding -> {
147149
val columnValue = if (this.hasColumn(column)) this[column] else null
148-
149150
if (columnValue != null) {
150-
var curr = intoEntity.implementation
151-
for ((i, prop) in binding.withIndex()) {
152-
if (i != binding.lastIndex) {
153-
var child = curr.getProperty(prop.name) as Entity<*>?
154-
if (child == null) {
155-
child = Entity.create(prop.returnType.classifier as KClass<*>, parent = curr)
156-
curr.setProperty(prop.name, child)
157-
}
158-
159-
curr = child.implementation
160-
}
161-
}
162-
163-
curr.setProperty(binding.last().name, columnValue)
151+
intoEntity.implementation.setColumnValue(column, columnValue)
164152
}
165153
}
166154
}

0 commit comments

Comments
 (0)