https://kotlinlang.org logo
#exposed
Title
# exposed
m

martmists

01/19/2022, 12:23 PM
How do I check columns for null or set them to nullable values? table:
Copy code
object CommentTable : LongIdTable() {
    val post = reference("post", PostTable)
    val parent = optReference("parent", CommentTable)
    val author = reference("author", UserTable)
    val content = text("content")
    val created = datetime("created")
    val updated = datetime("updated")
}
but when doing
CommentTable.parent eq null
I get
Copy code
Overload resolution ambiguity: 
public open fun <T : Comparable<TypeVariable(T)>, E : EntityID<TypeVariable(T)>?> ExpressionWithColumnType<TypeVariable(E)>.eq(t: TypeVariable(T)?): Op<Boolean> defined in org.jetbrains.exposed.sql.SqlExpressionBuilder
public open fun <T> ExpressionWithColumnType<TypeVariable(T)>.eq(t: TypeVariable(T)): Op<Boolean> defined in org.jetbrains.exposed.sql.SqlExpressionBuilder
d

dave08

01/19/2022, 2:11 PM
Add
.nullable()
to the column definition
except for
reference
then use
optReference
m

martmists

01/19/2022, 2:28 PM
as you can see that's what I did
✔️ 1
d

dave08

01/19/2022, 2:29 PM
You have a reference to the CommentTable itself?
I think there's a special construct for that...
In the DAO docs there's this for parent-child references
Copy code
object NodeTable : IntIdTable() {
    val name = varchar("name", 50)
}
object NodeToNodes : Table() {
    val parent = reference("parent_node_id", NodeTable)
    val child = reference("child_user_id", NodeTable)
}
I wonder if the fact you're referencing the table itself causes the problem?
Ooh... it seems not to know which of the two overloads to use...
The parent column is an
EntityID
not an
Int
by the way. So maybe there's some kind of empty instance of it to denote null instead of
null
?
I don't have my project using exposed open now, so I can't really check...
m

martmists

01/19/2022, 2:49 PM
The EntityID is nullable though, so why would it be a non-null value?
d

dave08

01/19/2022, 2:50 PM
And you can't even set it to null in an update statement?
m

martmists

01/19/2022, 3:21 PM
nope
5 Views