문제

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')
도움이 되었습니까?

해결책

the last item is the answer, class = class_name works even though it is technically a list. Worked like a charm. I did hit a unique error while checking this out, when doing key lookups you cannot use IN and !=.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top