summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2020-09-15 12:23:01 +0000
committerRaf Geens <raf@odoo.com>2020-09-16 08:33:19 +0000
commit6ae421f551ee36afa836494bc8563fc9276ab31e (patch)
tree5cd8503e9289707e9e8afbe07ae78acaea9516e6
parent549d159a836229f634be04131db947b275240edb (diff)
[IMP] doc: related fields do not support chained x2m dependencies
The behavior isn't exactly undefined: it will appear to work if the relation refers to only 1 instance. If there are multiple it will give results for 1 instance and ignore the others. This behavior should not be relied upon, hence I'm documenting it as undefined. I confirmed this with mat from the ORM team. Even better would be to raise an error or warning if `related` is used in this context. closes odoo/odoo#57270 closes odoo/odoo#57797 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com> Signed-off-by: Raf Geens <raf-odoo@users.noreply.github.com> Co-authored-by: Raf Geens <raf@odoo.com>
-rw-r--r--doc/reference/orm.rst22
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/reference/orm.rst b/doc/reference/orm.rst
index 1ef0b5ca422..7d2b3bd1ac6 100644
--- a/doc/reference/orm.rst
+++ b/doc/reference/orm.rst
@@ -332,6 +332,28 @@ dependencies are modified.
.. note:: The related fields are computed in sudo mode.
+.. warning::
+
+ You cannot chain :class:`~odoo.fields.Many2many` or :class:`~odoo.fields.One2many` fields in ``related`` fields dependencies.
+
+ ``related`` can be used to refer to a :class:`~odoo.fields.One2many` or
+ :class:`~odoo.fields.Many2many` field on another model on the
+ condition that it's done through a ``Many2one`` relation on the current model.
+ ``One2many`` and ``Many2many`` are not supported and the results will not be
+ aggregated correctly::
+
+ m2o_id = fields.Many2one()
+ m2m_ids = fields.Many2many()
+ o2m_ids = fields.One2many()
+
+ # Supported
+ d_ids = fields.Many2many(related="m2o_id.m2m_ids")
+ e_ids = fields.One2many(related="m2o_id.o2m_ids")
+
+ # Won't work: use a custom Many2many computed field instead
+ f_ids = fields.Many2many(related="m2m_ids.m2m_ids")
+ g_ids = fields.One2many(related="o2m_ids.o2m_ids")
+
.. _reference/fields/automatic:
Automatic fields