1

I'm trying to select the rows from a table based on a nullable referenced column. If you replace the reference with just a standard integer column and keep it nullable, it handles the eq just fine. I've also tried replacing the reference with optReference, but that didn't make a difference.

The error is given by the compiler.

None of the following functions can be called with the arguments supplied.
Expression<in EntityID<Int>?>.eq(Expression<in EntityID<Int>?>)   where T = EntityID<Int>?, S1 = EntityID<Int>?, S2 = EntityID<Int>? for    infix fun <T, S1 : T?, S2 : T?> Expression<in S1>.eq(other: Expression<in S2>): Op<Boolean> defined in org.jetbrains.exposed.sql.SqlExpressionBuilder
ExpressionWithColumnType<T>.eq(T)   where T cannot be inferred for    infix fun <T> ExpressionWithColumnType<T>.eq(t: T): Op<Boolean> defined in org.jetbrains.exposed.sql.SqlExpressionBuilder
ExpressionWithColumnType<EntityID<Int>>.eq(Int?)   where T = Int for    infix fun <T : Comparable<T>> ExpressionWithColumnType<EntityID<T>>.eq(t: T?): Op<Boolean> defined in org.jetbrains.exposed.sql.SqlExpressionBuilder

A basic working example showing the error given by Intellij.

object A : IntIdTable("a") {
    val n = varchar("n", 255)
    val x = reference("x", B).nullable()
}

object B : IntIdTable("b") {
    val i = varchar("m", 255)
    val y = integer("y")
}

fun main() {
    connectToDatabase()

    transaction {
        SchemaUtils.createMissingTablesAndColumns(A, B)

        A.select { A.x eq 1 }
    }
}

The equivalent sql I'm want it to run is:

select * from test.a as a where a.x = 1;
3
  • Try to replace reference("x", B).nullable() with optReference("x", B) Commented Dec 27, 2019 at 8:59
  • @Tapac I did try optReference and it didn't make a difference. Commented Jan 15, 2020 at 1:34
  • Yep - running into the same issue. Commented Jan 21, 2020 at 1:41

1 Answer 1

1

A.x is not a Column<Int>, its type is actually Column<EntityID<Int>>.

It looks like you need to write the query as

A.select { A.x eq EntityID(1, B) }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.