Entities and Unique Keys

1 view
Skip to first unread message

Marko Vuksanovic

unread,
May 21, 2008, 12:42:33 PM5/21/08
to Google App Engine
I've seen that it is not possible to query the datastore by Name/Id
column,.. so i used selfReference property.

def Company(db.Model)
company_id = db.SelfReference()

Then I used method store to save the entity and got the key (the doc
say the put method returns the id of the entity)

key = company.put()

company.company_id = key
company.put()

this saves the key in the datastore but i can't find out how to query
by that key

i tried

SELECT * FROM Company WHERE company_id =
<value_displayed_in_the_data_viewer_in_the_admin_console>

but this does not return any results. I need this information so that
i can pass it as a parameter in a url.

Any idea how i could query by that property....

Thanks

Edoardo Marcora

unread,
May 21, 2008, 12:48:10 PM5/21/08
to Google App Engine
> I've seen that it is not possible to query the datastore by Name/Id
> column,.. so i used selfReference property.

Sure you can... pass the id/key_name from your url param to
Model.get_by_id(id) or Model.get_by_key_name(key_name)

it's all well explained here http://code.google.com/appengine/docs/datastore/modelclass.html#Model_get_by_id

Dado
Reply all
Reply to author
Forward
0 new messages