Can a Google App Engine projection query return entities?

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 request that returns only a list of keys for photos?

 photos = db.GqlQuery("SELECT photo FROM Like WHERE created < DATETIME(2013, 1, 1, 0, 0, 0)").fetch(10) 

The above code creates:

 BadValueError: Unsupported data type (<class 'models.Photo'>) 
+4
source share
2 answers

Sorry my first answer was wrong. There is a real problem with projection queries - ReferenceProperty is not yet supported. Alfred is studying this; since the 1.6.6 preliminary SDK came out today, and it was already in the 1.6.5 SDk. I doubt that we will fix this in 1.6.6, but maybe 1.6.6.

As workarounds, you can use db.ListProperty (db.Key), which is a list of keys (you should store only one key) or StringProperty, whose value is str () of the key.

+1
source

It looks like your Photo class has not been imported yet.

+1
source

Source: https://habr.com/ru/post/1412032/


All Articles