房间数据库关系中的WHERE子句

时间:2020-10-29 00:51:17

标签: java sql android-studio relationship android-room

我在一个房间db中有一个表关系,看起来像这样

public class CategoryWithExpenses {

    @Embedded
    public Category category;

    @Relation(parentColumn = "id", entityColumn = "category_id")
    public List<DailyExpense> dailyExpense;
}

我的模特类别:

@Entity(tableName = "categories", indices = {@Index(value = {"name"}, unique = true)})
public class Category implements Parcelable {

    @PrimaryKey(autoGenerate = true)
    public int id;

    @ColumnInfo(name = "name")
    public String name;
}

我的DailyExpense模型如下:

@Entity(tableName = "daily_expenses")
public class DailyExpense implements Parcelable {

    @PrimaryKey(autoGenerate = true)
    public int id;

    @ColumnInfo(name = "name")
    public String name;

    @ColumnInfo(name = "amount")
    public float amount;

    @ColumnInfo(name = "description", defaultValue = "")
    public String description;

    @ColumnInfo(name = "currency", defaultValue = "tjs")
    public String currency;

    @ColumnInfo(name = "category_id")
    public int category_id;

    @ColumnInfo(name = "addedMonth")
    public String addedMonth;

    @ColumnInfo(name = "created_at")
    public String created_at;
}

现在我想通过DailyExpense中的addMonth获取所有类别和相关的DailyExpenses过滤。你能帮我吗?

0 个答案:

没有答案