Skip to content

Commit

Permalink
fix: EXPOSED-565 Subquery alias with id fails to use correct alias wi…
Browse files Browse the repository at this point in the history
…th eq (#2258)

* fix: EXPOSED-565 Subquery alias with id fails to use correct alias with eq

A fix for using mapIdComparison() with aliased table had been implemented, but
it did not fully cover the case when the right-hand side of the comparison involved
an unwrapped id column value. The latter was still using the delegate table associated
with the column type, instead of the invoking alias expression's alias table
identifier.

* fix: EXPOSED-565 Subquery alias with id fails to use correct alias with eq

- Add test that uses CompositeID on right-hand side

* fix: EXPOSED-565 Subquery alias with id fails to use correct alias with eq

- Remove unnecessary (this as Column<*>) cast
  • Loading branch information
bog-walk committed Sep 28, 2024
1 parent fb98340 commit ae28c53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ interface ISqlExpressionBuilder {
val table = (columnType as EntityIDColumnType<*>).idColumn.table as IdTable<T>
val entityID = EntityID(t, table)
return if ((this as? Column<*>)?.isEntityIdentifier() == true) {
table.mapIdComparison(entityID, ::EqOp)
this.table.mapIdComparison(entityID, ::EqOp)
} else {
EqOp(this, wrap(entityID))
}
Expand Down Expand Up @@ -382,7 +382,7 @@ interface ISqlExpressionBuilder {
val table = (columnType as EntityIDColumnType<*>).idColumn.table as IdTable<T>
val entityID = EntityID(t, table)
return if ((this as? Column<*>)?.isEntityIdentifier() == true) {
table.mapIdComparison(entityID, ::NeqOp)
this.table.mapIdComparison(entityID, ::NeqOp)
} else {
NeqOp(this, wrap(entityID))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ class AliasesTests : DatabaseTestsBase() {
counter[tester.id].isNotNull() and (counter[tester.id] eq t1)
}.single()
assertEquals(99, result2[counter[tester.amount]])

val result3 = counter.selectAll().where {
(counter[tester.id] eq t1.value) or (counter[tester.id] neq 123)
}.single()
assertEquals(99, result3[counter[tester.amount]])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,15 @@ class CompositeIdTableEntityTest : DatabaseTestsBase() {

val smallCity = Towns.alias("small_city")

val result = smallCity.selectAll().where {
val result1 = smallCity.selectAll().where {
smallCity[Towns.id].isNotNull() and (smallCity[Towns.id] eq townAId)
}.single()
assertNull(result[smallCity[Towns.population]])
assertNull(result1[smallCity[Towns.population]])

val result2 = smallCity.select(smallCity[Towns.name]).where {
smallCity[Towns.id] eq townAId.value
}.single()
assertEquals(townAValue[Towns.name], result2[smallCity[Towns.name]])
}
}

Expand Down

0 comments on commit ae28c53

Please sign in to comment.