I'm wondering if this is possible with the DAO API...
# exposed
j
I'm wondering if this is possible with the DAO API. What I'm trying to achieve is a single DAO class which references two tables in a certain way. Here is an example:
Copy code
object Vehicles : IdTable<String>() {
    override val id = varchar("id", length = 3072).uniqueIndex().entityId()
    override val primaryKey = PrimaryKey(id)
    val name = varchar("name", length = 4096)
}

object VehicleProperties : IdTable<String>() {
    override val id = reference("vehicle_id", Vehicles).uniqueIndex()
    override val primaryKey = PrimaryKey(id)
    val numberOfWheels = integer("number_of_wheels")
    val numberOfWindows = integer("number_of_windows")
}

class Vehicle(id: EntityID<String>) : Entity<String>(id) {
    val name by Vehicles.name
    var properties: Map<String, Int> // Key: Vehicle property name, value: vehicle property value
}
Basically, I want the
Vehicle
class to have a
properties
property which gets its data from the corresponding entry with the matching ID in the
VehicleProperties
table.
Alternatively, I would be okay with having
properties
be of some type
VehicleProps
like so:
Copy code
class VehicleProps(id: EntityID<String>) : Entity<String>(id) {
    var numberOfWheels by VehicleProperties.numberOfWheels
    var numberOfWindows by VehicleProperties.numberOfWindows
}
But I'm not quite sure how to do that either
I've ommitted the
EntityClass
companion objects for brevity
I was able to get this working using a second class to hold the Properties. The first class references the second with a
backReferenceOn
variable