According to the docs: http://code.google.com/appengine/docs/python/datastore/datamodeling.html#References the automatically created reverse reference object is a Query object, so there is possible iteration over it and making fetch calls.
But: I have one model:
class User(db.Model):
name = db.StringProperty()
...
and second model:
class Thing(db.Model):
owner = db.ReferenceProperty(User)
...
And when I try to access reverse reference:
for thing in user.thing_set:
...
or:
user.thing_set.fetch(100)
I get an exception like this:
<type 'exceptions.TypeError'>: '_ReverseReferenceProperty' object is not iterable
or like this:
<type 'exceptions.AttributeError'>: '_ReverseReferenceProperty' object has no attribute 'fetch'
Am I doing something wrong or there was some change in appengine? I'm pretty sure that previously it worked like a Query. There is even an example on the docs page, that shows the same usage as mine:
for obj in obj1.secondmodel_set:
# ...
Additionaly getting the query without reverse reference works ok:
things = Thing.all().filter('owner =', user)
Both methods (iterating and fetch) should work. To debug, you might want to log (or print):
print dir(user)
[..., 'thing_set', ...]
print dir(user.thing_set)
[..., '__iter__', ... , 'fetch', ...]
just to see what the objects contain... and that might give you a hint of what could be going wrong.
A couple of ideas:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With