Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Google App Engine, what is the difference between Model.get(key) and Model.get_by_key_name(key_names)?

Does get(key) require the entity key and get_by_key_name(key_names) require the key_name?

like image 695
ehfeng Avatar asked Jul 12 '09 22:07

ehfeng


1 Answers

There is a difference. An Entity in the datastore is identified by a combination of its Kind, its parent, and its identifier. (link) The "identifier" can either be a number or a string. A Key object contains both the identifier and the parent information. So when you call get(), there is just one argument - the Key object. When you call get_by_key_name, notice that there are 2 arguments - one is the key_name, one is the parent.

So a Key is an object with several parts, whereas a key name is just a string. To make things more confusing, a Key object can be encoded as a string.

like image 178
Peter Recore Avatar answered Nov 03 '22 02:11

Peter Recore