Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way to change the parent of a record in google app engine datstore

Given

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

Say I have a nested hierarchy

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

where a's parent is root, b's parent is a, c's parent is b etc.

Is there a simple way by which I could move node y from x to b such that z1 and z2 continue to remain children of y:

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

That would mean I simply change y's parent.

However, if that is not possible than it would require

  1. creating a new record ny = Category(parent=b, name=y) and
  2. recursively for each child of y creating a new record that has ny as a parent and
  3. than deleting y and its children.
like image 784
molicule Avatar asked Apr 30 '09 18:04

molicule


People also ask

What is Datastore in Google App Engine?

Datastore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. Datastore features include: Atomic transactions. Datastore can execute a set of operations where either all succeed, or none occur. High availability of reads and writes.

How do I delete a entity in Datastore?

const taskKey = datastore. key('Task'); await datastore. delete(taskKey);

What is the query language we can use with Datastore?

The Python Datastore API provides two classes for preparing and executing queries: Query uses method calls to prepare the query. GqlQuery uses a SQL-like query language called GQL to prepare the query from a query string.


1 Answers

The parent relationship is encoded in an entity's key, and the key is immutable once created, so no, you can't change the key of an existing entity. In order to do so, you need to reinsert all the relevant items with new keys.

like image 120
Nick Johnson Avatar answered Nov 15 '22 22:11

Nick Johnson