Question

In Google App Engine, datastore modelling, I would like to ask how can I check for null value of a property with class UserProperty? for example: I have this code:

class Entry(db.Model):
  title = db.StringProperty()
  description = db.StringProperty()
  author = db.UserProperty()
  editor = db.UserProperty()
  creationdate = db.DateTimeProperty()

When I want to check those entries that have the editor is not null, I can not use this kind of GqlQuery

query = db.GqlQuery("SELECT * FROM Entry " +
                    "WHERE editor IS NOT NULL" +
                                    "ORDER BY creationdate DESC")
    entries = query.fetch(5)

I am wondering if there is any method for checking the existence of a variable with UserProperty? Thank you!

Was it helpful?

Solution

query = db.GqlQuery("SELECT * FROM Entry WHERE editor > :1",None)

However, you can't ORDER BY one column and have an inequality condition on another column: that's a well-known GAE limitation and has nothing to do with the property being a UserProperty nor with the inequality check you're doing being with None.

Edit: I had a != before, but as @Nick pointed out, anything that's != None is > None, and > is about twice as fast on GAE (since != is synthesized by union of < and >), so using > here is a worthwhile optimization.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top