views:

38

answers:

2

Given a class-like relationship:

class A(db.Model):
    pass

class B(A):
    pass

Can I get all of the base class? The query:

models.A.all().fetch(1)

returns an empty list.

+1  A: 

The datastore does not record inheritance, per se: it stores the B entities as being of kind B. You can get all (direct, proper) subclasses of A with A.__subclasses__() (if you want indirect subclasses as well you'll need to do the same with each of these, and so forth, recursively, until you stop getting subclasses), and perform all the .all queries on them.

Alex Martelli
+2  A: 

The datastore doesn't natively support this sort of polymorphism - but you can use the polymodel class to do this. Just inherit from PolyModel instead of Model and things will behave more or less as you expect them to.

Nick Johnson