Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursive Relationship with Google App Engine and BigTable

In a classic relational database, I have the following table:

CREATE TABLE Person(
    Id int IDENTITY(1,1) NOT NULL PRIMARY KEY,
    MotherId int NOT NULL REFERENCES Person(Id),
    FatherId int NOT NULL REFERENCES Person(Id),
    FirstName nvarchar(255))

I am trying to convert this table into a Google App Engine table. My issue is with the fields MotherId and FatherId. I tried the code below, but no chance. Python says that it doesn't know the object type Person.

class Person(db.Model):
    mother = db.ReferenceProperty(Person)
    father = db.ReferenceProperty(Person)
    firstName = db.StringProperty()

Does someone know how we can model a recursive relationship in a Google App Engine table? How could I work around the limitation of App Engine?

UPDATE I want to expand the problem a little bit... What if I wanted to add a collection of children?

children = db.SelfReferenceProperty(collection_name='children_set')
dad.children.append(childrenOne)

I tried this and it doesn't work. Any idea what I am doing wrong?

Thanks!

like image 724
Martin Avatar asked Jun 02 '09 05:06

Martin


People also ask

Is bigtable relational?

Bigtable is not a relational database. It does not support SQL queries, joins, or multi-row transactions. If you need full SQL support for an online transaction processing (OLTP) system, consider Cloud Spanner or Cloud SQL.

Is bigtable a key value database?

Bigtable is a key/value store, not a relational store. It does not support joins, and transactions are supported only within a single row.

Is Bigtable distributed outside of Google?

Yes. It must be purchased in the app store. Yes, it is distributed by thrid-party venders.


1 Answers

I think that you want SelfReferenceProperty here

class Person(db.Model):
    mother = db.SelfReferenceProperty(collection_name='mother_set')
    father = db.SelfReferenceProperty(collection_name='father_set')
    firstName = db.StringProperty()

Alternatively, you can put the Mother and Father relations in separate classes.

like image 81
Nicolas Dumazet Avatar answered Sep 24 '22 06:09

Nicolas Dumazet