具有两个表的 GQL

发布于 2024-08-17 11:21:51 字数 190 浏览 2 评论 0原文

你好,我正在 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 技术交流群。

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

发布评论

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

评论(2

合约呢 2024-08-24 11:21:52

App Engine 数据存储区不支持联接,因此您将无法使用 GQL 解决此问题。您可以使用两种获取方式,一种用于客户端,一种用于请求,也可以使用 ReferenceProperty 来建立两个实体之间的关系。

如果您需要建模一对多关系,可以使用引用属性来完成。对于您的情况,它看起来像这样:

class Client(db.Model):
    email = db.UserProperty()
    name = db.StringProperty()

class Request(db.Model):
    client = db.ReferencePrpoerty(Client, collection_name='requests')
    issue = db.StringProperty()

任何具有与其关联的请求的客户端实体都会自动获取一个名为 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:

class Client(db.Model):
    email = db.UserProperty()
    name = db.StringProperty()

class Request(db.Model):
    client = db.ReferencePrpoerty(Client, collection_name='requests')
    issue = db.StringProperty()

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.

囚你心 2024-08-24 11:21:52

using this models:

class Client(db.Model):
    email = db.StringProperty()
    name = db.StringProperty()

class Request(db.Model):
    client = db.ReferenceProperty(Client, collection_name='requests')
    issue = db.StringProperty()    

通过此代码可以查询数据

from modelos import Client,Request

ctes=Client.all().filter("email =","[email protected]")

for ct in ctes:
   allRequest4ThisUser=Request.all().filter("client =",ct)
   for req in allRequest4ThisUser:
     print req.issue

using this models:

class Client(db.Model):
    email = db.StringProperty()
    name = db.StringProperty()

class Request(db.Model):
    client = db.ReferenceProperty(Client, collection_name='requests')
    issue = db.StringProperty()    

With this code can query the data

from modelos import Client,Request

ctes=Client.all().filter("email =","[email protected]")

for ct in ctes:
   allRequest4ThisUser=Request.all().filter("client =",ct)
   for req in allRequest4ThisUser:
     print req.issue
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文