Search code examples
kotlinktorkotlin-exposed

Kotlin Exposed Unsolved Reference: referencedOn


I'm trying to develop a REST API using Ktor framework and after going through some tutorials and the official documentation I just implemented a sample code. I'm also using Kotlin Exposed and I'm just trying to make some database tables and connect them. So I made two classes UsersRepo and RolesRepo both extending IntIdTable. I just want to have a one to one relationship between these 2 tables so I did something like this:

object UsersRepo : IntIdTable("userId") {
    val displayName = varchar("display_name", 256)
    val role = reference("role", RolesRepo)
}

and then, I just wanted to implement the Entity class for the User and the IDE doesn't recognise the referencedOn keyword.enter image description here

I don't know what I'm missing here. I'm using Ktor and Kotlin 1.4.0 and Kotlin Exposed version 0.25.1

    implementation "org.jetbrains.exposed:exposed-core:$exposed_version"
    implementation "org.jetbrains.exposed:exposed-dao:$exposed_version"
    implementation "org.jetbrains.exposed:exposed-jdbc:$exposed_version"

Solution

  • The issue is that you referenced the table instead of the entity for your role. It should be var role by Role referencedOn UsersRepo.role