0

I'm creating a database where I have the following hierarchy: Subject -> Topics -> Pages. I know that there will only ever be two subjects. Arts and Science lets say. Is it possible for me to create a topic where I set the parent key to a string "Arts", so that I don't have to create a db.model Subject with only two values?

Also, if I do have to make a class Subject inheriting from db.Model, is there a way I can avoid putting in any parameters since the key.name will be the name of the subject?

Alxander
  • 323
  • 1
  • 3
  • 9

2 Answers2

0

Just specifying an ancestor key is enough, the ancestor itself does not have to exist.

You don't have to provide any properties in a Model.

class MyModel(db.Model):
    pass

And lastly I gather you are just starting out, so I would recommend you switch to ndb before you go to far.

Tim Hoffman
  • 12,976
  • 1
  • 17
  • 29
0

Tim's answer is correct. I just wanted to add to the answer that it's poor design to have all your entities under two ancestors.

Ancestors exist in cases where you need to ensure transactional integrity. That might be true for you, in which case, ignore this.

The use of ancestors limits the write performance for all entities within that ancestor tree. If you don't really need to lock down all of these entities, you might not actually use an ancestor, but just a normal attribute.

dragonx
  • 14,963
  • 27
  • 44
  • Thanks I'll keep that in mind, though how does it ensure transactional integrity? – Alxander Jul 27 '13 at 00:54
  • I would agree. If you are likely to have lots of concurrent writes across lots of entities that share an ancestor you will more than likely get contention. – Tim Hoffman Jul 27 '13 at 01:36
  • It's kinda too long to explain here. If you're really curious, read up on Google's BigTable whitepapers. From what I understand, which may not be 100% accurate, entities under the same ancestor get stored on the same servers, so they can be locked for transactions. But it also means you lose out on the normally distributed performance of the datastore. – dragonx Jul 27 '13 at 03:01