Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like `ForeignKey` in Google App Engine's `webapp`?

I'm using Google App Engine with their webapp framework. Is there something like Django's ForeigKey in webapp? i.e. I have a model and I want it to have a property/field that points at another model. Possible?

like image 930
Ram Rachum Avatar asked Mar 01 '11 16:03

Ram Rachum


1 Answers

There is a db.ReferenceProperty. You need to be aware of two things when using it: automatic dereferencing (which is another datastore RPC call) and the entity being referenced is not required to exist (so you will need to manually check it).

When using db.ReferenceProperty make sure you use Appstats to avoid fetching entities in serial. Nick Johnson has an article that explains how to pre-fetch referenced entities.

like image 87
Robert Kluin Avatar answered Sep 28 '22 06:09

Robert Kluin