Google App Engine - query for arrays containing value

I have a GAE Datastore table with an array field in it (containing multiple rows). I would like to filter this table based on all array fields containing a specific row. How can i do this? I have not seen the "contains" operator in GQL, and the "in" operator works the other way around. Do I just need to iterate over all entities and perform validation?

(PS I use Python in my work with GAE).

+6
source share
1 answer

just use equals, for example:

class MyModel(db.Model): colors = db.StringListProperty() MyModel(colors=['red', 'blue']).put() MyModel(colors=['green', 'blue']).put() MyModel(colors=['red', 'green']).put() color = 'red' query = MyModel.gql('WHERE colors = :1', color) models = query.fetch(10) assert len(models) == 2 
+6
source

Source: https://habr.com/ru/post/953566/


All Articles