1

1対多の関係があるオブジェクトで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;

AssociateBusinessWithUser のような Business でメソッドを作成する必要がありますか? または、これをどのようにリンクする必要がありますか?

4

1 に答える 1

5

dbFlowVersion = '3.0.0-beta1' のコードは次のとおりです。私はあなたのクラスを簡素化します:

    @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 がすべての魔法を作成します。

于 2016-01-14T13:05:43.970 に答える