我一直在尝试使用 GreenDAO 创建数据库模型。当我尝试在不同的表之间创建多个关系时,问题就开始了。
基本上,我有一张Message
桌子,一张Conversation
桌子和一张User
桌子。
用户有一个消息列表,并且该消息有一个父对话。
我尝试编写此代码来创建数据库:
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);
}
运行此代码后,我收到此错误:
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)
这实际上是否意味着我不能为我的数据库中的每个表创建多个关系?!
我必须手动编写所有内容吗?