work around new sqlalchemy limitations
This commit is contained in:
parent
c14d250166
commit
60e17ab076
2 changed files with 14 additions and 8 deletions
|
@ -5,7 +5,7 @@ import os
|
|||
import unicodedata
|
||||
|
||||
from sqlalchemy.orm import load_only
|
||||
from sqlalchemy.sql.expression import text
|
||||
from sqlalchemy.sql.expression import text, column
|
||||
from sqlalchemy import func
|
||||
|
||||
from oxtornado import actions
|
||||
|
@ -58,8 +58,13 @@ def find(data):
|
|||
qs = models.Find.query.filter_by(key=q['group'])
|
||||
if items is None or items.first():
|
||||
if items is not None:
|
||||
qs = qs.filter(models.Find.item_id.in_(items))
|
||||
values = list(qs.values('value', 'findvalue', 'sortvalue'))
|
||||
ids = [i[0] for i in items.with_entities(column('id'))]
|
||||
qs = qs.filter(models.Find.item_id.in_(ids))
|
||||
values = list(qs.values(
|
||||
column('value'),
|
||||
column('findvalue'),
|
||||
column('sortvalue'),
|
||||
))
|
||||
for f in values:
|
||||
value = f[0]
|
||||
findvalue = f[1]
|
||||
|
|
|
@ -5,7 +5,7 @@ import unicodedata
|
|||
import sqlalchemy.orm.exc
|
||||
from sqlalchemy.sql import operators
|
||||
from sqlalchemy.orm import load_only
|
||||
from sqlalchemy.sql.expression import text
|
||||
from sqlalchemy.sql.expression import text, column
|
||||
|
||||
import utils
|
||||
import settings
|
||||
|
@ -14,6 +14,7 @@ from fulltext import find_fulltext
|
|||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_operator(op, type='str'):
|
||||
return {
|
||||
'str': {
|
||||
|
@ -135,7 +136,8 @@ class Parser(object):
|
|||
q = get_operator(op)(self._find.findvalue, v)
|
||||
if k != '*':
|
||||
q &= (self._find.key == k)
|
||||
ids = self._model.query.join(self._find).filter(q).options(load_only('id'))
|
||||
ids = self._find.query.filter(q).with_entities(column('item_id'))
|
||||
ids = [i[0] for i in ids]
|
||||
return self.in_ids(ids, exclude)
|
||||
elif k == 'list':
|
||||
nickname, name = v.split(':', 1)
|
||||
|
@ -269,5 +271,4 @@ class Parser(object):
|
|||
data.get('query', {}).get('operator', '&'))
|
||||
for c in conditions:
|
||||
qs = qs.filter(c)
|
||||
#print(qs)
|
||||
return qs
|
||||
|
|
Loading…
Reference in a new issue