Joshua Hansen
12/21/2023, 7:13 PMobject 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.Joshua Hansen
12/21/2023, 7:16 PMproperties
be of some type VehicleProps
like so:
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 eitherJoshua Hansen
12/21/2023, 7:17 PMEntityClass
companion objects for brevityJoshua Hansen
12/26/2023, 10:41 PMbackReferenceOn
variable