Build a GQL query (for Google App Engine) that has a condition on ReferenceProperty

允我心安 提交于 2019-12-03 15:42:20

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())

An even easier thing to do is to change the model definition by adding the 'collection_name' field to the ReferenceProperty:

station = db.ReferenceProperty(Station, required=True, collection_name="schedules")

Then you can just do:

foo.schedules

whenever you want to get all the stations' schedules.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!