可以使用GQL IN运算符来搜索列表属性中有项目的实体吗?

时间:2011-08-04 23:16:37

标签: python google-app-engine gql datastore

我的意思是,如果你有一个模型,就像这样(Python)

class MahModel(db.Model):

具有标签属性(例如)

    tags = db.StringListProperty()

我可以在查询中执行此类操作吗? WHERE 'x' IN tags

如果没有,我可以使用哪种解决方法?

我的实际代码如下:
Ad.gql(“WHERE paid = True AND deliver = False AND'”+ cat +“'IN board ORDER BY date ASC LIMIT 1”)。get()

board是一个列表,我希望与cat变量匹配

这给了我这个错误:
ad_ = Ad.gql("WHERE paid = True AND delivered = False AND '" + cat + "' IN boards ORDER BY date ASC LIMIT 1").get()
File "C:\Programme\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1208, in gql
*args, **kwds)
File "C:\Programme\Google\google_appengine\google\appengine\ext\db\__init__.py", line 2296, in __init__
self._proto_query = gql.GQL(query_string, _app=app, namespace=namespace)
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 195, in __init__
if not self.__Select():
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 813, in __Select
return self.__From()
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 834, in __From
return self.__Where()
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 846, in __Where
return self.__FilterList()
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 871, in __FilterList
return self.__FilterList()
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 871, in __FilterList
return self.__FilterList()
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 853, in __FilterList
self.__Error('Invalid WHERE Identifier')
File "C:\Programme\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 738, in __Error
(error_message, self.__symbols[self.__next_symbol]))
BadQueryError: Parse Error: Invalid WHERE Identifier at symbol 'tf2'

1 个答案:

答案 0 :(得分:1)

WHERE tags = 'x'

将返回列表中至少有一次“x”的任何实体。