Dimitar Kostov
07/09/2024, 12:38 PMval condition = when {
name != null ->
Op.build { Users.name like "%name%" }
country != null ->
Op.build { Users.country like "%country%" }
else -> null
}
Users.selectAll().where(condition)
This will result in: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun <T, R> DeepRecursiveFunction<TypeVariable(T), TypeVariable(R)>.invoke(value: TypeVariable(T)): TypeVariable(R) defined in kotlinAdamW
07/09/2024, 12:53 PMselectAll().where(null)
Dimitar Kostov
07/09/2024, 1:18 PMpublic final var where: org.jetbrains.exposed.sql.Op<kotlin.Boolean>? /* compiled code */
private final set(value: org.jetbrains.exposed.sql.Op<kotlin.Boolean>?)
Dimitar Kostov
07/09/2024, 1:19 PMAdamW
07/09/2024, 1:23 PMwhere
, which doesn’t have a nullable overload. So you’d run into that next.
Anyway, it could be that you have an issue with name shadowing. Could you try to make a minimal repro?AdamW
07/09/2024, 1:28 PMname
in your query 😅Dimitar Kostov
07/09/2024, 1:30 PMDimitar Kostov
07/09/2024, 1:36 PMDimitar Kostov
07/09/2024, 1:36 PMChantal Loncle
07/09/2024, 1:44 PMelse
branch to generate? If all users should be returned when both name and country are null, Op.TRUE
could be used in the final branch instead to generate WHERE TRUE
.Dimitar Kostov
07/09/2024, 1:46 PMval query = condition?.let { StarWarsFilms.selectAll().where(condition) } ?: StarWarsFilms.selectAll()
Dimitar Kostov
07/09/2024, 1:46 PMChantal Loncle
07/09/2024, 1:52 PM