[IMP] orm: some improvement on previous commit on orm search with order_by (still needs fixing):

Avoid depending on implicit ordering of tables in a query but still allow basic sorting by inherited fields

bzr revid: odo@openerp.com-20100826114531-ajbukfsu9u3glhz5
This commit is contained in:
Olivier Dony 2010-08-26 13:45:31 +02:00
parent e69414c7ec
commit 1dec419270
2 changed files with 9 additions and 9 deletions

View File

@ -71,7 +71,7 @@ class expression(object):
raise ValueError('Bad domain expression: %r' % (exp,))
self.__exp = exp
self.__field_tables = {} # used to store the table to use for the sql generation. key = index of the leaf
self.__all_tables = []
self.__all_tables = set()
self.__joins = []
self.__main_table = None # 'root' table. set by parse()
self.__DUMMY_LEAF = (1, '=', 1) # a dummy leaf that must not be parsed or sql generated
@ -106,7 +106,7 @@ class expression(object):
return [(left, 'in', rg(ids, table, parent or table._parent_name))]
self.__main_table = table
self.__all_tables.append(table)
self.__all_tables.add(table)
i = -1
while i + 1<len(self.__exp):
@ -129,7 +129,7 @@ class expression(object):
working_table = main_table.pool.get(main_table._inherit_fields[fargs[0]][0])
if working_table not in self.__all_tables:
self.__joins.append('%s.%s=%s.%s' % (working_table._table, 'id', main_table._table, main_table._inherits[working_table._name]))
self.__all_tables.append(working_table)
self.__all_tables.add(working_table)
main_table = working_table
field = working_table._columns.get(fargs[0], False)

View File

@ -2192,6 +2192,9 @@ class orm(orm_template):
:param tables: list of table._table names enclosed in double quotes as returned
by _where_calc()
:param where_clause: current list of WHERE clause params
:return: (table, where_clause, qualified_field) where ``table`` and ``where_clause`` are the updated
versions of the parameters, and ``qualified_field`` is the qualified name of ``field``
in the form ``table.field``, to be referenced in queries.
"""
current_table = self
while field in current_table._inherit_fields and not field in current_table._columns:
@ -2199,7 +2202,7 @@ class orm(orm_template):
parent_table = self.pool.get(parent_model_name)
self._inherits_join_add(parent_model_name, tables, where_clause)
current_table = parent_table
return (tables, where_clause)
return (tables, where_clause, '"%s".%s' % (current_table._table, field))
def _parent_store_compute(self, cr):
if not self._parent_store:
@ -3824,11 +3827,8 @@ class orm(orm_template):
elif (o in self._inherit_fields):
parent_obj = self.pool.get(self._inherit_fields[o][0])
if getattr(parent_obj._columns[o], '_classic_read'):
# Allowing inherits'ed field for server side sorting
inherited_tables, inherit_join = self._inherits_join_calc(o, tables, where_clause)
if inherited_tables:
inherited_sort_table = inherited_tables[-1]
order_by = inherited_sort_table + '.' + order
# Allowing inherits'ed field for server side sorting, if they can be sorted by the dbms
inherited_tables, inherit_join, order_by = self._inherits_join_calc(o, tables, where_clause)
limit_str = limit and ' limit %d' % limit or ''
offset_str = offset and ' offset %d' % offset or ''