odoo/odoo#162656

Created by Framework (ORM), Chong Wang (cwg)
label
odoo-dev:master-base-check-cycle-sql-cwg
head
8490bc253304c56932b0e50f443df42c43e85526
target
master
merged
3 weeks ago by Framework (ORM), Raphael Collet

[IMP] base: _has_cycle replaces _check_recursion in SQL

Implement the detection of cycles using a single recursive SQL query, for the sake of performance. The query starts from `self.ids` and follows the relation defined by the field. The good part is that we can use the same query for both many2many and many2one fields.

The new method `_has_cycle()` returns `True` if some records are reachable from `self` and are part of a cycle, even if those records are not part of `self`. This is acceptable, because this method is called after modifying some records, and we assume that the unchanged records did not contain a loop beforehand.