Do not use relation field from default order when fetching One2Many records

The records are already ordered by the field id to be grouped later so such
order clause has no impact on the result.
But they require joins that may not be needed otherwise.

Closes #14716
This commit is contained in:
Cédric Krier
2026-03-26 18:00:24 +01:00
parent 6a412267b0
commit df765aee83
+3 -1
View File
@@ -154,7 +154,9 @@ class One2Many(Field):
if self.order:
order += self.order
elif Target._order:
order += Target._order
order += [
(oexpr, otype) for oexpr, otype in Target._order
if not oexpr.startswith(f'{self.field}.')]
if reference_key:
references = ['%s,%s' % (model.__name__, x) for x in ids]
clause = [(self.field, 'in', references)]