Oleg Babichev
09/12/2024, 8:20 AMHousehold::pets
.
Which workaround I can imaginge.
In one project I needed different states of one entity, I used for it state(json)
column with actual data and discriminator(enum)
column for resolving different states in different kotlin classes (I created custom json parser for it). Positive moment is that you need only one table, and one Exposed Table/Entity definion. Disadvantage is that you store json in the database (so if you have IDs inside state, or you want make complicated queries you may have problems)
Another option I see is creating table pet
with columns for every specific pet. For example:
object Dog : IntIdTable("og")
object Cat : IntIdTable("cat")
object Pet : IntIdTable("pet") {
val dog = integer("dog").references(Dog.id).nullable()
val cat = integer("cat").references(Cat.id).nullable()
}
This table could be used as an PetEntity
with nullable links to other optional pets (DogEntity
, CatEntity
. Inside PetEntity
the special function could be defined, that will return just any non null Pet
. Here is the problem I see, is that adding any new pet is quite painful: you need to add new table, new column to pet
table, new Table/Entity pair, and not forget update PetEntity
to resolve new type of pets.Ivan Gomes
09/23/2024, 5:08 PM