具有两个表的 GQL
你好,我正在 google appengine 中做一个非常小的应用程序,我使用 python。 我的问题是我有两个使用 de db.model 的表(“客户端”和“请求”)。表“client”具有电子邮件和姓名字段,表“requests”具有电子邮件和问题字段。我想做一个查询,如果两个表中的电子邮件相同,则为每个请求返回电子邮件、问题和客户名称。有人可以帮忙吗?
Hello i am doing a very small application in google appengine and i use python.
My problem is that i have two tables using de db.model ("clients" and "requests"). The table "client" has got the email and name fields and the table "requests" has got the email and issue fields. I want to do a query that returns for each request the email, issue and client name, if the email is the same in the two tables. Can anyone help, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
App Engine 数据存储区不支持联接,因此您将无法使用 GQL 解决此问题。您可以使用两种获取方式,一种用于客户端,一种用于请求,也可以使用 ReferenceProperty 来建立两个实体之间的关系。
如果您需要建模一对多关系,可以使用引用属性来完成。对于您的情况,它看起来像这样:
任何具有与其关联的请求的客户端实体都会自动获取一个名为 requests 的属性,该属性是一个查询对象,它将返回所有具有 < em>client 字段设置为您正在处理的特定客户端实体。
您可能还想确保创建请求实体的代码将每个新实体设置为将特定用户的客户端实体作为其祖先。将这些关联项目保留在同一实体组中可能有助于性能原因和事务。
The app engine datastore does not support joins, so you will not be able to solve this problem with GQL. You can use two gets, one for client and one for request, or you can use a ReferenceProperty to establish a relationship between the two entities.
If you need to model a one-to-many relationship, you can do it with a reference property. For your case, it would look something like this:
Any Client entity that has a Request associated with it will automatically get a property called requests which is a Query object that will return all Request entities that have a client field set to the particular Client entity you are dealing with.
You might also want to make sure that the code that creates Request entities set each new entity to have the Client entity for the particular user as its ancestor. Keeping these associated items in the same entity group could be helpful for performance reasons and transactions.
using this models:
通过此代码可以查询数据
using this models:
With this code can query the data