【发布时间】:2013-07-16 09:56:34
【问题描述】:
为了在这两个类之间使用 ORMLite 建立多对多关系:
@DatabaseTable(tableName = "test1")
public class Test1 {
@ForeignCollectionField
private ForeignCollection<Test2> test2Collection;
}
@DatabaseTable(tableName = "test2")
public class Test2 {
@ForeignCollectionField
private ForeignCollection<Test1> test1Collection;
}
我在创建表时遇到了 ORMLite 的问题,不知道此类之间的外键..
为了建立这种关系,我必须在每个类上添加一个 ForeignDatabaseField,如下所示:
@DatabaseTable(tableName = "test1")
public class Test1 {
@DatabaseField(foreign = true, foreignAutoRefresh = true)
private Test2 test2;
@ForeignCollectionField
private ForeignCollection<Test2> test2Collection;
}
@DatabaseTable(tableName = "test2")
public class Test2 {
@DatabaseField(foreign = true, foreignAutoRefresh = true)
private Test1 test1;
@ForeignCollectionField
private ForeignCollection<Test1> test2Collection;
}
好像是一种奇怪的方式?
【问题讨论】:
-
对不起,我不明白这个问题。如果没有一些共享信息,您将如何表示与
Test1集合相关联的Test2的所有权? -
是的,我需要链接到第二个对象主键的外键。所以这就是我在第二个例子中所做的......?!
标签: android many-to-many dao ormlite