开发者

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

开发者 https://www.devze.com 2023-02-13 23:42 出处:网络
I\'m using Google App Engine with their webapp fram开发者_C百科ework. 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 a

I'm using Google App Engine with their webapp fram开发者_C百科ework. 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?


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.


I was just looking at this myself; db.ReferenceProperty is definitely the way to go.

I found a decent looking explanation here; Modeling Entity Relationships

0

精彩评论

暂无评论...
验证码 换一张
取 消