https://kotlinlang.org logo
#exposed
Title
# exposed
d

dave08

11/10/2021, 3:06 PM
I have a very complex set of relationships of a bunch of tables, and from table A, I want to be able to access A.B.C.D.name... it'd be a pity to have to create an entity for each one, load them all and traverse them all just to access that field's value...
t

tapac

11/10/2021, 3:07 PM
Is there one-to-one relation between tables? Do you need only read access?
d

dave08

11/10/2021, 3:09 PM
They're all linked through foreign keys, and I need read, and preferrably write only if all the entities between exist... I wouldn't need that field to be initialized in
new { }
though.
It's a type of virtual field I'm looking for to be able to simplify my domain's model.
t

tapac

11/10/2021, 3:12 PM
DAO supports updates only on the Entity table, but for read you can override
dependsOnTable
and
dependsOnColumns
in EnityClass:
Copy code
override val dependsOnTables = ItemTable innerJoin CategoriesTable
override val dependsOnColumns = ItemTable.columns + CategoriesTable.name
Then just delegate to CategoriesTable.name:
Copy code
val categoryName: String by CategoriesTable.name
👍🏼 1
d

dave08

11/10/2021, 4:09 PM
That's already not bad! Just wondering why we need to let it know the dependencies if we already declare them in the Table, can't they be inferred? -- but this is probably liveable, until a ksp plugin to generate all the biolerplate code could be made...
--- Also, if there's already a join, would it be so hard to allow write access to it?