开发者

Can I find all of a certain base model in App Engine?

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜