gpt4 book ai didi

android - 数据库流中的一对多

转载 作者:行者123 更新时间:2023-11-29 15:09:02 25 4
gpt4 key购买 nike

我正在尝试将 DBFlow 与我有一对多关系(用户有很多业务)的对象一起使用,我在他们的官方 wiki 上关注教程,但它只是不想工作。

这是我的用户:

@Column
@PrimaryKey(autoincrement = true)
private Integer id;

@Expose
@Column
private Boolean allow_offline;

@Expose
@Column
private Integer user_level;

@Expose
@Column
private Integer account_validity;

@Expose
@Column
private Integer selected_business;

@Expose
@Column
private String user_id;

@Expose
@Column
private Boolean allow_print;

@Expose
@Column
private String email;

@Expose
private List<Business> businesses;

和我的生意

@Expose
@Column
@PrimaryKey
private Integer id;
@Expose
@Column
private String name;
@Expose
@Column
private Boolean is_zero_tax;
@Expose
@Column
private String header;
@Expose
@Column
private String footer;

我应该在 Business 中创建一个像 associateBusinessWithUser 这样的方法吗?或者我应该如何链接它?

最佳答案

这是 dbFlowVersion = '3.0.0-beta1' 的代码。我简化了你的类(class):

    @Table(database = DbFlowDataBase.class)
public class User extends BaseModel {

@PrimaryKey(autoincrement = true)
Integer id;

List<Business> businesses;

@OneToMany(methods = OneToMany.Method.ALL, variableName = "businesses")
public Field[] dbFlowOneTwoManyUtilMethod() {
if (businesses == null) {
businesses = SQLite.select()
.from(Business.class)
.where(Business_Table.userId.eq(id))
.queryList();
}
return businesses;
}

}

这是 Business.class:

@Table(database = DbFlowDataBase.class)
public class Business extends BaseModel {

@PrimaryKey(autoincrement = true)
public Integer id;

@Column
Integer userId;

}

请注意 dbFlowOneTwoManyUtilMethod 是所有魔法的创造者。

关于android - 数据库流中的一对多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33825496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com