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

Let's 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 them say that I have a Station object stored in var foo.

How do I assemble a GQL query that returns all Schedule objects with a link to the Station object that it refers to foo?

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

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

Once again foo- the object Station

+5
source share
2 answers

GQL, . GQL , :

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

, :

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

, , 'collection_name' ReferenceProperty:

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

:

foo.schedules

.

+7

All Articles