如何实现GreenDao表继承

如何实现GreenDao表继承

本文介绍了如何实现GreenDao表继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图创造一个所有表,以继承某个元素数据库不得不可能性有元数据。

I've been trying to create a database where all the tables inherit a certain element in order to have to possibility to have meta-data.

有对我的模型生成器加入所有的表声明此行

there for I added in the model generator in all the table declarations this line:

public Entity addSuperEntity(Schema schema) {
     Entity superEntity = schema.addEntity("superEntity");
     superEntity.addIdProperty().primaryKey();
     // SET RELATIONSHIP 1:m TO META DATA
}

public Entity addTable(Schema schema) {
    Entity mEntity = schema.addEntity("MyEntity");
    mEntity.setSuper("superEntity");
    mEntity.addIdProperty().PrimaryKey();
    // REST OF FIELDS
}

问题是:

现在我生成这个对我的Andr​​oid项目后,我怎样才能确保这仍然发生在现实生活中?我现在需要改变什么?

now after I generated this to my Android project, how can I make sure that this still happens in real life? do I need to change anything now?

官方文档没有关于继承的东西。

the official documentation doesn't have anything about inheritance.

推荐答案

继承是支持使用setSuperclass(串)非实体超类。另一种方法是使用实​​现的implementsInterface(字符串)接口。

Inheritance is supported for non-entity super classes using setSuperclass(String). An alternative is implementing interfaces using implementsInterface(String).

我更新了关于继承和接口的新节的一些细节的官方文档:
http://greendao-orm.com/documentation/modelling-entities/

I updated the official docs with some details in the new section on inheritance and interfaces:http://greendao-orm.com/documentation/modelling-entities/

这篇关于如何实现GreenDao表继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:34