Ankit Jaiswal
Ankit Jaiswal

Reputation: 23427

Google app engine: reverse reference lookups

Is reverse referencing possible in Google app engine? I am using app engine patch to develope an application and my model is something like:

class Portfolio(db.Model):
   user = db.ReferenceProperty(User)
   pic = db.BlobProperty()

Now, If I have the user object, is it possible to retrieve the pic associated with the users portfolio? i.e. the reverse reference from the User to Portfolio.

Upvotes: 1

Views: 351

Answers (2)

Piotr Duda
Piotr Duda

Reputation: 1815

Yes it is possible. By default you can access users portfolio through user.portfolio_set. Read here for more info: http://code.google.com/intl/pl/appengine/articles/modeling.html

Upvotes: 1

arikfr
arikfr

Reputation: 3361

Yes. You can access the pics, via:

user = User()
pics = user.portfolio_set

You can change the default name (which is modelname_set) by passing the collection_name argument to the ReferenceProperty constructor. For example:

class Portfolio(db.Model):
  user = db.ReferenceProperty(User, collection_name="Portfolio")

See more information and examples here: http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html

Upvotes: 1

Related Questions