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!
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.
Bigtable is a key/value store, not a relational store. It does not support joins, and transactions are supported only within a single row.
Yes. It must be purchased in the app store. Yes, it is distributed by thrid-party venders.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With