Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GreenDAO support multiple relations between tables

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?

like image 879
thepoosh Avatar asked Oct 23 '12 14:10

thepoosh


1 Answers

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.

like image 112
Markus Junginger Avatar answered Oct 23 '22 01:10

Markus Junginger