You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a simple reference table (Currencies) that I want a natural primary key on, and no incrementing integer key:
object Currencies : IdTable<String>("currency") {
val symbol : Column<String> = varchar("symbol",3)
override val id: Column<EntityID<String>> = symbol.entityId()
override val primaryKey = PrimaryKey(symbol)
}
I create an entity object:
class Currency(symbol: EntityID<String>) : Entity<String>(symbol) {
companion object : EntityClass<String, Currency>(Currencies)
var symbol by Currencies.symbol
}
However, if I try to refer to the symbol column I get an error:
val currency = Currency.get("USD")
println("Symbol property on Currency object is ${currency.symbol}")
.. Error: java.lang.IllegalStateException: Model.Currencies.symbol is not in record set
I then change the companion object to refer to the entity ID (Currencies.id instead of Currencies.symbol):
class Currency(symbol: EntityID<String>) : Entity<String>(symbol) {
companion object : EntityClass<String, Currency>(Currencies)
var symbol by Currencies.id
}
Then I can refer to the symbol column but I need to use the awkward currency.symbol.value to get the declared string value of the column...
val currency = Currency.get("USD")
println("Symbol column is a string, but here it is: ${currency.symbol::class.qualifiedName}")
println("I need to do currency.symbol.value in order for it to work: ${currency.symbol.value}")
Output:
Symbol column is a string, but here it is: org.jetbrains.exposed.dao.DaoEntityID
I need to do currency.symbol.value in order for it to work: USD
How do I configure the companion object so that I can refer to the symbol property without having to know that it's a primary key and use symbol.value to get to the declared column type of String?
If I use an integer incrementing column for Id then it works fine; but in this domain model I really want to use the natural key.
Thank you!
The text was updated successfully, but these errors were encountered:
Hello,
I have a simple reference table (Currencies) that I want a natural primary key on, and no incrementing integer key:
I create an entity object:
However, if I try to refer to the
symbol
column I get an error:I then change the companion object to refer to the entity ID (
Currencies.id
instead ofCurrencies.symbol
):Then I can refer to the
symbol
column but I need to use the awkwardcurrency.symbol.value
to get the declared string value of the column...How do I configure the companion object so that I can refer to the
symbol
property without having to know that it's a primary key and usesymbol.value
to get to the declared column type of String?If I use an integer incrementing column for Id then it works fine; but in this domain model I really want to use the natural key.
Thank you!
The text was updated successfully, but these errors were encountered: