Convert element joined domains into domain when searching for OR-ed domain

The content of joined domains can be a single clause, so it must be converted
into a domain before calling search_domain.

Closes #12460
This commit is contained in:
Cédric Krier
2023-08-10 13:55:00 +02:00
parent 4fffd30011
commit 2d8cc458fd
2 changed files with 21 additions and 0 deletions
+1
View File
@@ -1655,6 +1655,7 @@ class ModelSQL(ModelStorage):
if joined_domains is not None:
union_tables = []
for sub_domain in joined_domains:
sub_domain = [sub_domain] # it may be a clause
tables, expression = cls.search_domain(sub_domain)
if rule_domain:
tables, domain_exp = cls.search_domain(
+20
View File
@@ -823,6 +823,26 @@ class ModelSQLTestCase(unittest.TestCase):
self.assertIn('UNION', str(Model.search(domain, query=True)))
self.assertNotIn('UNION', str(query_without_split))
@with_transaction()
def test_search_or_to_union_with_in_clause(self):
"Test searching for 'OR'-ed domain with in clause"
pool = Pool()
Model = pool.get('test.modelsql.search.or2union')
record, = Model.create([{
'name': "Foo",
'targets': [('create', [{
'name': "Bar",
}]),
],
}])
domain = ['OR',
('name', '=', 'Bar'),
('targets.id', 'in', [t.id for t in record.targets]),
]
self.assertEqual(Model.search(domain), [record])
@with_transaction()
def test_search_or_to_union_order_eager_field(self):
"""