It is a simple two step process. (1) Do a query that gets you all of the Location s with the birthplace that you're interested in.
(2) For each Location from (1), use its name to do a query that gets you the Person s. Remember, a given GAE datastore query looks at only one kind of entity. If you want to solve a problem with only one query, all of the information that you need to select an entity must be in said entity. (Even that's not enough - there are also restrictions on what kind of constraints you can place on the selected entities.) On Feb 9, 9:55 pm, adelevie <[email protected]> wrote: > Thanks for the suggestion of reworking the models, but I'd really like > the way to do it given my models. I changed the names of the entities > and properties so as not to give away what I'm trying to do. > > On Feb 10, 12:45 am, Bill <[email protected]> wrote: > > > > > I don't understand why you are modeling it that way. Why have the > > ReferenceProperty in Location? > > > Given your case of wanting all people with a given birthplace, it > > seems like this makes sense: > > > class Person(db.Model): > > name = db.StringProperty() > > birthplace = db.ReferenceProperty(Location, default="unknown", > > collection_name='born_here') > > > class Location(db.Model): > > place = db.StringProperty() > > > Since a person is likely only born in one place, you put the reference > > with the Person. > > Now you can do: > > birthplace = my_person.birthplace # gets Location > > and > > some_location.born_here # list of Person born here > > > On Feb 9, 9:27 pm, adelevie <[email protected]> wrote: > > > > I know the datastore is not relational but this should still be > > > simple. > > > > I have two models: > > > > class Person(db.Model): > > > name = db.StringProperty() > > > > class Location(db.Model): > > > birthplace = db.StringProperty() > > > name = db.ReferenceProperty() > > > > So I want to be able to select all People given a birthplace. I tried > > > messing with keys, but to no avail. > > > > thanks, > > > Alan- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
