I have already tried use polymorphic in greenDao, but not successful. How to use polymorphic in greenDao ?
for example:
I have a table "my_favorites", in that i can store id foreign key of Events, Pictures, Music ... ?I hope for your help!
I'm afraid this is not supported by greendao at the moment.
You will have to store the keys to a normal 'LongProperty' without any 'toOne' or 'toMany' and in a second column you will have to save a discriminator value (i.e. the referenced classname).
Then you will have to build the queries yourself (i.e. in the 'KEEP-SECTION' of your 'my_favorites'.
public Object getDetail() throws ClassNotFoundException {
if (daoSession== null) {
throw new DaoException("Entity is detached from DAO context");
}
return daoSession.load(Class.forName(getDiscriminator()), getMyDetailId());
}
you can use ToMany relation in your DB. Look at this tutorial
Entity customer = schema.addEntity("Customer");
customer.addIdProperty();
customer.addStringProperty("name").notNull();
Entity order = schema.addEntity("Order");
order.setTableName("ORDERS"); // "ORDER" is a reserved keyword
order.addIdProperty();
Property orderDate = order.addDateProperty("date").getProperty();
Property customerId = order.addLongProperty("customerId").notNull().getProperty();
order.addToOne(customer, customerId);
ToMany customerToOrders = customer.addToMany(order, customerId);
customerToOrders.setName("orders");
customerToOrders.orderAsc(orderDate);