Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement table inheritance in 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
}

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.

like image 634
thepoosh Avatar asked Oct 25 '12 13:10

thepoosh


1 Answers

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/

like image 58
Markus Junginger Avatar answered Oct 16 '22 18:10

Markus Junginger