coredump
coredump

Reputation: 3107

Google app engine GQL query key

I do not really understand what does the key.from_path() do.

If you could explained it a little better and more concise then here.

Also, the parent parameter intrigues me .

Upvotes: 0

Views: 270

Answers (1)

Paul Collingwood
Paul Collingwood

Reputation: 9116

Every item in the datastore has a key.

k = Key.from_path('User', 'Boris', 'Address', 9876)

You can either create that key and then use it to retrieve the object in the datastore that has that key or you can save an object to the datastore with that key for later retrieval.

address_k is a key after this operation.

address_k = db.Key.from_path('Employee', 'asalieri', 'Address', 1)
address = db.get(address_k)

Then the second line gets the datastore object that has that key.

Parent simply says that this object is a child of another object. So when you set the parent it becomes part of the key also.

address = Address(parent=employee)

You could have multiple address objects, all with the same parent, employee. Your employee might have many homes! Read this: https://developers.google.com/appengine/docs/python/datastore/entities#Ancestor_Paths

Upvotes: 1

Related Questions