Allow to read related xxx2Many

Rational

For now, the ModelStorage.read can be used to read direct field and related field from xxx2One or Reference. This API has been developed mainly for the client needs. But sometimes when integrating with other system, it will be more performant if we could read also other related fields.

Proposal

Allow to pass to ModelStorage.read xxx2Many related fields.
Here is an example of such call and the result:

read([id,…], {'name', 'language.name', 'addresses', 'addresses.country','addresses.country.code',  'addresses.subdivision'})
-> [{'id': 1, 'name': 'foo', 'language.name': 'French', 'addresses': [3, …], 'addresses.': [{'id': 3, 'country': 2, 'country.code': 'FR', 'subdivision': 5}, {…}, …]}, …]

So as soon as there are xxx2Many related fields, the result value for the field is a list of dictionary with the requested value plus always the id.
:warning: the name of the key is suffixed by a . to not collide with legacy result.
The API for xxx2One is not changed.
Of course the access rights must still be enforced.

Implementation

https://bugs.tryton.org/issue7888

1 Like

I think we should replace the syntax for xxx2One and Reference also by ending dot followed by a dictionary of value. This will bring more consistency and I think it worth the backward compatibility break.

Will the clients be updated to follow this new API?
I’m wonering if it will be a good improvement for rendering forms with some XXX2Many fields, for example the party.party form.

It is needed to keep the rec_name tuning.

I do not see how we could make improvement without losing the lazy loading. We need to know how much records a xxx2Many has before deciding how much should be loaded.

This topic was automatically closed after 13 days. New replies are no longer allowed.