开发者

Is an ancestor automatically "put" in the datastore?

开发者 https://www.devze.com 2023-03-13 17:44 出处:网络
I\'m just starting with Google App Engine, and I\'m a bit confused at the first datastore example in the tutorial.

I'm just starting with Google App Engine, and I'm a bit confused at the first datastore example in the tutorial.

In this example, each time a greeting is put in the datastore, its parent is set to a key built from the guestbook name :

 greeting = Greeting(parent=guestbook_key(guestbook_name))

with

def guestbook_key(guestbook_name=None):
    """Constructs a datastore key for a Guestbook entity with guestbook_name."""
    return db.Key.from_path('Guestbook', guestbook_name or 'default_guestbook')

What bugs me is that the guestbook_name itself is never explicitly put in the data开发者_开发技巧store. So are the greetings children of something that is not in the datastore ? Or is the guestbook_name somehow stored automatically ?


The example also says:

There is no need to create the "Guestbook" entity before setting it to be the parent of another entity. In this example, the parent is used as a placeholder for transaction and consistency purposes.

Also, from: http://khaidoan.wikidot.com/google-app-engine-datastore-entity-group

You can create an entity with an ancestor path without first creating the parent entity. To do so, you create a Key for the ancestor using a kind and key name, then use it as the parent of the new entity. All entities with the same root ancestor belong to the same entity group, whether or not the root of the path represents an actual entity.

0

精彩评论

暂无评论...
验证码 换一张
取 消