This is next step to this question, where I need to run queries and apply filters.
Here is my Model
from google.appengine.ext import db
Class Car(db.Model):
name=db.StringProperty()
model=db.StringProperty()
mileage=db.IntegerProperty()
person = db.ReferenceProperty(Person, collection_name='person')
Class Person(db.Model):
name=db.StringProperty()
age=db.IntegerProperty()
Question : For a Person I want to get all the cars he own
Approach : Get all the cars and apply filter on person whose name is “Random”
I tried the following but it doesn’t work
s = Car.all()
s.filter('person.name =', 'Random') # It fails here
result = s.fetch(1)[0] # just first result for now
print result.text
print result.votes
print result.page.language
How can I make this query run?
Thank you
You can only use filter on indexed attributes.
person.nameis from other entity! In sql you would need to use join (which is impossible when data grows big), in google bigtable like in many other non-relational databases tablesjoinis not possible. Luckily your case is very simple, you can select all cars if you know persons key:If you had used a more reasonable value for
collection_nameyou could access all cars like this: