Skip to content

Commit

Permalink
Incorrect inList #1490
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Apr 15, 2022
1 parent 00de8d6 commit 627b3b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ interface ISqlExpressionBuilder {
/** Checks if this expression is equals to any element from [list]. */
@Suppress("UNCHECKED_CAST")
@JvmName("inListIds")
infix fun <T : Comparable<T>> Column<EntityID<T>>.inList(list: Iterable<T>): InListOrNotInListBaseOp<EntityID<T>> {
infix fun <T : Comparable<T>, ID: EntityID<T>?> Column<ID>.inList(list: Iterable<T>): InListOrNotInListBaseOp<EntityID<T>?> {
val idTable = (columnType as EntityIDColumnType<T>).idColumn.table as IdTable<T>
return inList(list.map { EntityIDFunctionProvider.createEntityID(it, idTable) })
return SingleValueInListOp(this, list.map { EntityIDFunctionProvider.createEntityID(it, idTable) }, isInList = true)
}

/** Checks if this expression is not equals to any element from [list]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class InListOrNotInListBaseOp<V> (
}

class SingleValueInListOp<T>(
expr: ExpressionWithColumnType<T>,
expr: ExpressionWithColumnType<out T>,
list: Iterable<T>,
isInList: Boolean = true
) : InListOrNotInListBaseOp<T>(expr, list, isInList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase
import org.jetbrains.exposed.sql.tests.TestDB
import org.jetbrains.exposed.sql.tests.shared.assertEquals
import org.jetbrains.exposed.sql.tests.shared.entities.EntityTests
import org.junit.Test
import kotlin.test.assertNull

Expand Down Expand Up @@ -157,6 +158,24 @@ class SelectTests : DatabaseTestsBase() {
}
}

@Test
fun testInList08() {
withTables(EntityTests.Posts) {
val board1 = EntityTests.Board.new {
this.name = "Board1"
}

val post1 = EntityTests.Post.new {
this.board = board1
}

EntityTests.Post.new { }

val result = EntityTests.Posts.select { EntityTests.Posts.board inList listOf(board1.id) }.singleOrNull()?.get(EntityTests.Posts.id)
assertEquals(post1.id, result)
}
}

@Test
fun testInSubQuery01() {
withCitiesAndUsers { cities, _, _ ->
Expand Down

0 comments on commit 627b3b8

Please sign in to comment.