From c68045e4972a60305f8187477255adee47e8a0a2 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 19 Jan 2012 16:10:12 +0100 Subject: [PATCH] [FIX] expression: properly care for implicitly defined m2m fields used in search() domains Now that m2m fields may be defined without explicitly specifying the name of the relationship table and its foreign key columns, all access to these internal names should be done via m2m._sql_names(). This seems better than lazily initializing these internal names and hoping that nothing accesses them before the init. bzr revid: odo@openerp.com-20120119151012-c38k5zl7rqherhth --- openerp/osv/expression.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index c81ee897891..9da51ce744c 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -526,12 +526,13 @@ class expression(object): self.__exp[i] = ('id', o2m_op, select_distinct_from_where_not_null(cr, field._fields_id, field_obj._table)) elif field._type == 'many2many': + rel_table, rel_id1, rel_id2 = field._sql_names(working_table) #FIXME if operator == 'child_of': def _rec_convert(ids): if field_obj == table: return ids - return select_from_where(cr, field._id1, field._rel, field._id2, ids, operator) + return select_from_where(cr, rel_id1, rel_table, rel_id2, ids, operator) ids2 = to_ids(right, field_obj) dom = child_of_domain('id', ids2, field_obj) @@ -559,11 +560,11 @@ class expression(object): else: call_null_m2m = False m2m_op = 'not in' if operator in NEGATIVE_TERM_OPERATORS else 'in' - self.__exp[i] = ('id', m2m_op, select_from_where(cr, field._id1, field._rel, field._id2, res_ids, operator) or [0]) + self.__exp[i] = ('id', m2m_op, select_from_where(cr, rel_id1, rel_table, rel_id2, res_ids, operator) or [0]) if call_null_m2m: m2m_op = 'in' if operator in NEGATIVE_TERM_OPERATORS else 'not in' - self.__exp[i] = ('id', m2m_op, select_distinct_from_where_not_null(cr, field._id1, field._rel)) + self.__exp[i] = ('id', m2m_op, select_distinct_from_where_not_null(cr, rel_id1, rel_table)) elif field._type == 'many2one': if operator == 'child_of':