I’ve read a lot about how I need to rethink implementing entities and joins when developing for AppEngine, and I still can’t figure out how to do this:
I’ve 3 entities. Tag has many Tweets and User Follow many Tags.
I would like to get all Tweets that is Tagged with tags that a User follows.
I thought eliminating Tags entity and using StringListProperty might work as this:
Tweets.all().filter(‘tag IN”, user.tags)
However, as in the ListProperty documentations indicated, this won’t work! as because a query can’t compare two lists.
A query cannot compare two list values. There is no way to test two lists for equality without testing each element for membership separately.
Any idea how to structure the entities in order I can be able to answer the question:
How to get all Tweets that is Tagged with tags that a User follows?
Thanks
You’re not trying to compare two lists – you’re checking for intersection. The query you list will do that, with one major caveat: IN filters are split up into multiple sub-queries, which are executed independently by the backend, with a maximum of 30 sub-queries.
That is, if your user follows 3 tags [‘foo’, ‘bar’, ‘baz’], doing the above is equivalent the union of: