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

zero_coding

08/26/2020, 11:21 AM
Hi all I have defined a table with custom primary key:
Copy code
object Genders : Table() {
    val value: Column<String> = varchar("value", 1)
    val description: Column<String> = varchar("description", 20)
    override val primaryKey = PrimaryKey(value)
}
As next, I would like to create an Entity class for it and I have tried:
Copy code
class Gender(v: EntityID<String>) : Entity<String>(v) {
    companion object : EntityClass<String, Gender>(???)

    var value by Genders.value
    var description by Genders.description
}
k

Kenneth Wußmann

08/26/2020, 11:32 AM
EntityClass
expects an `IdTable`: For example
Copy code
object Genders : IdTable<String>() {
    override val id = varchar("value", 20).entityId()
    val description: Column<String> = varchar("description", 20)
    override val primaryKey: PrimaryKey? = PrimaryKey(id)
}
class Gender(id: EntityID<String>) : Entity<String>(id) {
    companion object : EntityClass<String, Gender>(Genders)
    var description by Genders.description
}
You can read more about that here: https://github.com/JetBrains/Exposed/wiki/DAO#overview
👍 1
z

zero_coding

08/26/2020, 11:38 AM
How do you know regarding the
IdTable
? In doc, it does not mention about the
IdTable
.
aha
ok I've got it
Wow awesome
Thanks so much
2 Views