GreenDAO support multiple relations between tables

孤人 提交于 2020-01-02 00:59:47

问题


I've been trying to create a DB model using GreenDAO. the problem started when I tried to create more than one relationship between a different tables.

basically, I have a Message table, a Conversation table and a User table.

the User has a list of messages, and the message has a parent conversation.

I tried writing this code for creating the DB:

    private static void addUser(Schema schema) {
            user = schema.addEntity("User");
            userId = user.addIdProperty().getProperty();
            user.addStringProperty("facebookId").unique().index();

            user.addStringProperty("firstName");
            user.addStringProperty("lastName");
            user.addStringProperty("fullName");
            user.addStringProperty("photoUrl");
    }

    private static void addMessage(Schema schema) {
            message = schema.addEntity("Message");
            messageId = message.addIdProperty().getProperty();
            message.addStringProperty("messageId").primaryKey();

            message.addDateProperty("date");
            message.addStringProperty("content");
            message.addStringProperty("typeString");
    }

    private static void addConversation(Schema schema) {
          conversation = schema.addEntity("Conversation");
          conversation.addIdProperty();

          conversation.addStringProperty("conversationId");
          // REST OF THE CODE
    }

    private static void fakeRelationship(Schema schema) {
            Property author = message.addLongProperty("author").getProperty();
            Property parent = message.addLongProperty("parent").getProperty();

            message.addToOne(user, author);
            message.addToOne(conversation, parent);

            user.addToMany(message, author);
            conversation.addToMany(message, parent);
    }

after running this code, I got this error:

Exception in thread "main" java.lang.RuntimeException: Currently only single FK columns are supported: ToOne 'parent' from Message to Conversation
at de.greenrobot.daogenerator.ToOne.init3ndPass(ToOne.java:91)
at de.greenrobot.daogenerator.Entity.init3rdPassRelations(Entity.java:557)
at de.greenrobot.daogenerator.Entity.init3ndPass(Entity.java:550)
at de.greenrobot.daogenerator.Schema.init3ndPass(Schema.java:185)
at de.greenrobot.daogenerator.DaoGenerator.generateAll(DaoGenerator.java:94)
at de.greenrobot.daogenerator.DaoGenerator.generateAll(DaoGenerator.java:79)
at com.glidetalk.dao.generator.GlideDaoGenerator.main(GlideDaoGenerator.java:27)

does this actually meen that I can't create more than one relation for each table in my DB?!

do I have to write everything manually?


回答1:


What you try to do is supported by greenDAO and your code looks good, too. I copied it into my workspace and it executed perfectly fine. So I guess something is wrong in the code you left out.



来源:https://stackoverflow.com/questions/13032987/greendao-support-multiple-relations-between-tables

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