In general, it\'s better to do a single query vs. many queries for a given object. Let\'s say I have a bunch of \'son\' objects each with a \'father\'. I get all the \'son\'
You can find the answer by studying the sources of appengine.ext.db in your download of the App Engine SDK sources -- and the answer is, no, there's no special-casing as you require: the __get__
method (line 2887 in the sources for the 1.3.0 SDK) of the ReferenceProperty
descriptor gets invoked before knowing if .key()
or anything else will later be invoked on the result, so it just doesn't get a chance to do the optimization you'd like.
However, see line 2929: method get_value_for_datastore
does do exactly what you want!
Specifically, instead of son.father.key()
, use Son.father.get_value_for_datastore(son)
and you should be much happier as a result;-).