Allow to read related xxx2Many


(Cédric Krier) #1

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


Newsletter January 2019
(Cédric Krier) #2

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.


(Sergi Almacellas Abellana) #3

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.


(Cédric Krier) #4

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.


(Cédric Krier) #5

(Cédric Krier) #6

(Cédric Krier) #7

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