本文介绍了构建一个在ReferenceProperty上具有条件的GQL查询(适用于Google App Engine)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下模型:

$ p $ class Schedule(db.Model):
tripCode = db。 StringProperty(required = True)
station = db.ReferenceProperty(Station,required = True)
arrivalTime = db.TimeProperty(required = True)
departureTime = db.TimeProperty(required = True)

假设我有一个存放在var foo

如何组装一个GQL查询,该查询返回所有Schedule对象,并引用由 foo



这是我最好的(尽管错误的)尝试形成这样的查询:

  myQuery =SELECT * FROM Schedule where station =+ str(foo.key())

再次 foo 是一个电台对象

解决方案

您不应该将用户数据插入到GQL字符串中字符串替换。 GQL支持参数替换,所以你可以这样做:

  db.GqlQuery(SELECT * FROM Schedule WHERE station = $ 1, foo.key())

或者使用Query接口:

  Schedule.all()。filter(station =,foo.key())


Say I have the following model:

class Schedule(db.Model):
    tripCode = db.StringProperty(required=True)
    station = db.ReferenceProperty(Station, required=True)    
    arrivalTime = db.TimeProperty(required=True)
    departureTime = db.TimeProperty(required=True)

And let's say I have a Station object stored in the var foo.

How do I assemble a GQL query that returns all Schedule objects with a reference to the Station object referenced by foo?

This is my best (albeit incorrect) attempt to form such a query:

myQuery = "SELECT * FROM Schedule where station = " + str(foo.key())

Once again foo is a Station object

解决方案

You shouldn't be inserting user data into a GQL string using string substitution. GQL supports parameter substitution, so you can do this:

db.GqlQuery("SELECT * FROM Schedule WHERE station = $1", foo.key())

or, using the Query interface:

Schedule.all().filter("station =", foo.key())

这篇关于构建一个在ReferenceProperty上具有条件的GQL查询(适用于Google App Engine)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:17