如何从 GAE 中的 ReferenceProperty 中仅获取密钥(而不加载实体)?

发布于 2024-10-10 03:37:55 字数 120 浏览 0 评论 0原文

当访问 ReferenceProperty 时,它会从数据存储区加载一个实体,但有时我只想使用引用的模型密钥,并且不想支付引用模型加载的额外成本。

有没有办法只访问 ReferenceProperty 上的键?

When ReferenceProperty is accessed it loads an entity from datastore, but sometimes I'd like only to use a referenced model key only and I don't want to pay the additional cost of referenced model loadup.

Is there a way to access just the key on a ReferenceProperty?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2024-10-17 03:37:55

给定后

class Foo(db.Model):
    bar = db.ReferenceProperty()

foo = Foo.get_by_id(1) # or however you get it

您可以检索键 foobar ReferenceProperty,如下所示:

key = Foo.bar.get_value_for_datastore(foo)

Given

class Foo(db.Model):
    bar = db.ReferenceProperty()

and

foo = Foo.get_by_id(1) # or however you get it

you can retrieve the key foo's bar ReferenceProperty like so:

key = Foo.bar.get_value_for_datastore(foo)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文