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

大城市里の小女人 提交于 2020-01-02 04:00:09

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5157070/is-there-something-like-foreignkey-in-google-app-engines-webapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!