我对如何在DBFlow中声明外键感到困惑。在DBFlow(https://github.com/Raizlabs/DBFlow/blob/f2d90db39a4bf5ffcc0f22032ae20d5328b8d3c3/usage2/Relationships.md)的关系的入门页面中,它有 Queen 类的示例,但没有 Ant 的示例,也没有 Colony class。
有没有人拥有包含女王 + Ant + Colony 类的完整示例?
由于
答案 0 :(得分:2)
这是您想要的示例代码:
父表:
@Table(database = AppDatabase.class)
public class CafeWebContentCategories extends BaseModel {
@PrimaryKey
private int id;
@Column
private int categoryServerId;
@PrimaryKey
@Column
public int cafeServerId;
@Column
private String title;
@Column
private boolean isAuto;
public List<CafeWebChildContentCategories> subContentCategories;
@OneToMany(methods = {OneToMany.Method.ALL}, variableName = "subContentCategories")
public List<CafeWebChildContentCategories> getMyChannelSubContentCategories() {
if (subContentCategories == null || subContentCategories.isEmpty()) {
subContentCategories = SQLite.select()
.from(CafeWebChildContentCategories.class)
.where(CafeWebChildContentCategories_Table.parentId.eq(cafeServerId))
.queryList();
}
return subContentCategories;
}
public CafeWebContentCategories() {
}
// setters and getters
}
子表:
@Table(database = AppDatabase.class)
public class CafeWebChildContentCategories extends BaseModel {
@PrimaryKey
@Column
public int id;
@Column
public int categoryId;
@Column
@ForeignKey(tableClass = CafeWebContentCategories.class,
references = @ForeignKeyReference(columnName = "parentId", foreignKeyColumnName = "cafeServerId"))
public int parentId;
@Column
private String title;
public CafeWebChildContentCategories() {
}
// setters and getters
}
如果您对此有疑问,请询问我