Hi, I have an issue with DAO API. I have two table...
# exposed
v
Hi, I have an issue with DAO API. I have two tables one is
Phones
and another
Operations
. I have 1:N relationship.
Copy code
class PhoneDao(id: EntityID<Long>) : LongEntity(id) {
    companion object : LongEntityClass<PhoneDao>(PhoneTable)
    ...
    val operations by OperationsDao referrersOn OperationsTable.deviceId
and
Copy code
data object OperationsTable : LongIdTable("Operations") {
    val deviceId = reference("device_id", PhoneTable)
...
}
Copy code
class OperationsDao(id: EntityID<Long>) : LongEntity(id) {
    companion object : LongEntityClass<OperationsDao>(OperationsTable)

    var deviceId by OperationsTable.deviceId
and issue is I have stored device_id as compound string
Type_id
type - string prefix in my case is
Phone
and
id
relates to id from phones. Complete device_id string is
Phone_1
. I need to somehow cast or transform
Phone.id.toString()
https://pl.kotl.in/N5CQhMyfE
c
Hi @Václav Benes Could you clarify how/where you're storing
device_id
as a compound string? From the snippets I'm seeing
Phone.id
is a
Long
and I'm assuming that
PhonesTable
is also a
LongIdTable
, so where does the transformation need to happen? On insert, on mapping, or when retrieving from the database? I'm not sure it's exactly what you need, but it's possible to use
transform()
on an entity field mapping (Wiki). Here are some better test examples.
v
Yeap, device_id is a compound string, so I do join the operation and I need to concatenate device_id with Phone.id. I do operation when I retrieve data from db.
I check examples. Thank you.