How can I Query only __key__ on a Google Appengine PolyModel child?
- by Gabriel
So the situation is: I want to optimize my code some for doing counting of records. So I have a parent Model class Base, a PolyModel class Entry, and a child class of Entry Article: How would I query Article.key so I can reduce the query load but only get the Article count.
My first thought was to use:
q = db.GqlQuery("SELECT __key__ from Article where base = :1", i_base)
but it turns out GqlQuery doesn't like that because articles are actually stored in a table called Entry.
Would it be possible to Query the class attribute? something like:
q = db.GqlQuery("select __key__ from Entry where base = :1 and :2 in class", i_base, 'Article')
neither of which work. Turns out the answer is even easier. But I am going to finish this question because I looked everywhere for this.
q = db.GqlQuery("select __key__ from Entry where base = :1 and class = :2", i_base, 'Article')