App Engine 数据存储区通过引用过滤器连接
我对 App Engine 数据存储区非常陌生,我无法弄清楚这一点。 我有这些模型: <代码>
class SomeUser(User):
name = db.StringProperty()
class Group(db.Model):
title = db.StringProperty()
date_started = db.DateTimeProperty(auto_now_add=True)
class GroupParticipant(db.Model):
group = db.ReferenceProperty(Group, collection_name = 'participants')
participant = db.ReferenceProperty(SomeUser)
is_owner = db.BooleanProperty()
<代码> 如何查询数据存储以获得如下结果:
Group.title, Group_owner, Number of participants/Group
group1, someuser1, 3
group2, someuser2, 4
I'm very new to App Engine Datastore and I could not figure this out.
I have these models:
class SomeUser(User):
name = db.StringProperty()
class Group(db.Model):
title = db.StringProperty()
date_started = db.DateTimeProperty(auto_now_add=True)
class GroupParticipant(db.Model):
group = db.ReferenceProperty(Group, collection_name = 'participants')
participant = db.ReferenceProperty(SomeUser)
is_owner = db.BooleanProperty()
How to query the datastore to get a result like this:
Group.title, Group_owner, Number of participants/Group
group1, someuser1, 3
group2, someuser2, 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根本没有连接。您必须手动获取所有数据。例如,您可以从
GroupParticipant
获取所有记录,然后循环获取所有Group
和SomeUser
(请注意,通过Key< 获取) /code> 非常快)
——
顺便说一句,可能最好使用不同的数据结构,就像
在这种情况下,您只需一个查询即可获取所有所需的数据
There is no joins at all. You have to fetch all data manually. For example you can fetch all records from
GroupParticipant
, and then fetch allGroup
andSomeUser
in loop (note that fetching byKey
is very fast)--
btw, probably it's better to use different data structures, like
at this case you can fetch all required data by just one query