Let’s say I have:
class Like(db.Model):
user = db.ReferenceProperty(User,collection_name='likes')
photo = db.ReferenceProperty(Photo,collection_name='likes_received')
created = db.DateTimeProperty(auto_now_add=True)
Is it possible to run a projection query that returns only a list of photo keys?
photos = db.GqlQuery("SELECT photo FROM Like WHERE created < DATETIME(2013, 1, 1, 0, 0, 0)").fetch(10)
The code above produces:
BadValueError: Unsupported data type (<class 'models.Photo'>)
I apologize, my first answer was wrong. There is a real problem with projection queries — ReferenceProperty is not (yet) supported. Alfred is looking into this; since the 1.6.6 prerelease SDK went out today and this was already present in the 1.6.5 SDk I doubt we’ll get this fixed in 1.6.6 but 1.6.7 is a possibility.
As workarounds, you could use db.ListProperty(db.Key), which is a list of keys (you’d store only one key), or a StringProperty whose value is the str() of the key.