how to implement table inheritance in GreenDao

痴心易碎 提交于 2019-12-10 13:48:09

问题


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
}

the question is:

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/13069614/how-to-implement-table-inheritance-in-greendao

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!