ORMLite Android中的一对多关系 [英] One-To-Many relationship in ORMLite Android
问题描述
如何在ORMLite Android中实现一对多关系?
How do I implement one-many relationship in ORMLite Android?
请查看示例
public class A {
private String name;
@DatabaseField (foreign = true, foreignAutoRefresh = true, columnName = "A")
private B b;
@DatabaseField(columnName = "author")
private String authorName;
}
public class B {
@DatabaseField(generatedId = true, columnName = "id")
private long id;
@DatabaseField(columnName = "name")
private String name;
@ForeignCollectionField
Collection<A> aees;
}
B有A的集合。我打电话给 dao .create(b);
B has collection of A. I am calling dao.create(b);
现在我创建b的dao,因为b包含所有数据。但表B仅使用数据创建,A永远不会创建。请帮助一下?
Now i create dao of b, since b has all the data. But the table B has only created with data, A is never created. Kindly could some one help?
推荐答案
现在我创建了b的dao,因为b包含所有数据。但表B仅使用数据创建,A永远不会创建。请帮助一下?
Now i create dao of b, since b has all the data. But the table B has only created with data, A is never created. Kindly could some one help?
对。您需要使用以下内容创建 A
项目:
Right. You need to create the A
items using:
for (A a : b.aees) {
aDao.create(a);
}
ORMLite不会自动为您创建这些。
ORMLite does not automatically create those for you.
您可以查看外国收集示例程序。
这篇关于ORMLite Android中的一对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!