我在一个房间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过滤。你能帮我吗?