From c4442e83410cda394d204e1dc706433822e991eb Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Tue, 15 Sep 2020 12:23:01 +0000 Subject: [PATCH] [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#57815 X-original-commit: 6ae421f551ee36afa836494bc8563fc9276ab31e Signed-off-by: Raf Geens Signed-off-by: Victor Feyens (vfe) Co-authored-by: Raf Geens --- doc/reference/orm.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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