Is there an easy way to change the parent of a record in the datstore of the Google App Engine

Considering

  class Category (db.Model):
    name = db.Stringproperty ()

Say I have a nested hierarchy

  -root
  | -a
  |  | -b
  |  | -c
  | -x
    | -y
      | -z1
      | -z2

where a parent root , b parent a , c parent b , etc.

Is there an easy way to move node y from x to b so that z1 and z2 continue to be children of y :

  -root
  | -a
  |  | -b
  |  | -c
  |  | -y
  |  | -z1
  |  | -z2
  | -x

This means that I just change the parent y .

However, if this is not possible, it will require

  • creating a new entry ny = Category(parent=b, name=y) and
  • recursively for each child y creating a new record with ny as the parent and
  • than removing y and its children.
+6
google-app-engine google-cloud-datastore
source share
1 answer

The parent relationship is encoded in the entity key, and the key is unchanged after creation, so no, you cannot change the key of an existing object. To do this, you need to again insert all the relevant elements with the new keys.

+6
source share

All Articles