I think the `EntityStore` would have been better i...
# komapper
d
I think the
EntityStore
would have been better if they were generated and defined ONCE and not just when trying to retrieve data... one can easily make a mistake and use the wrong thing as the one and the many... when declaring the entities and relations, we tend to check the db structures and make sure the relations are right, from then on, the querying should only give the RIGHT options for the situation...
t
Perhaps I do not fully understand your thoughts. What kind of API do you want?
d
I would really like to have some way to say, retrieve an address list and a list of telephone no's from a person w/o having to look each one up in its own list and stating the oneToMany relation in the querying code. One way might be to have an annotation:
Copy code
class Address {
...
   @KommapperForeignKey(Person::class)
   val personId: Int
that would let Komapper know at compile time how to link things, then the Meta class could maybe have extra fields to be used by the EntityStore to retrieve the appropriate thing for a certain field in a Person, say, a list of addresses (one to many or many to many, etc...) or a tutor (many to one).
t
Thanks for your explanation. Given complex cases such as SQL self-joins, I don’t think it is possible to link to other entities at compile time. Also, as a Komapper policy, I would like to be able to express relationships in queries, not entities.
d
I'm not really proposing to add a
@KomapperOneToMany
etc..., just a
@KomapperForeignKey
which would give a hint to help out expressing the relationships correctly in queries...
Maybe an extension property could be generated on the Entity class:
Copy code
fun Person.addresses(es: EntityStore): List<Address>
To help avoid a bunch of boilerplate map lookups?
And hint as to correctly using the store...
But maybe this is also too complex?
t
Oh, it’s an idea worth considering. Please give me some time.