相关疑难解决方法(0)

如何在Room中过滤嵌套关系?

让我们举个例子:我有一个表单,其中有几个部分,每个部分都有问题.侧面,我有答案映射到问题,他们有另一列,我想在查询时过滤:

数据库架构

所以我有以下实体:

@Entity(tableName = "sections")
public class Section {
    @PrimaryKey
    public long id;
    public String title;
}
@Entity(tableName = "questions")
public class Question {
    @PrimaryKey
    public long id;
    public String title;
    public long sectionId;
}
@Entity(tableName = "answers")
public class Answer {
    @PrimaryKey
    public long id;
    public long questionId;
    public int otherColumn;
}
Run Code Online (Sandbox Code Playgroud)

在DAO部分,我想要检索所有这些.

这是我想通过此查询填充的POJO:

class SectionWithQuestions {
    @Embedded
    public Section section;

    @Relation(parentColumn = "id", entityColumn = "sectionId", entity = Question.class)
    public List<QuestionWithAnswer> questions;

    public static class QuestionWithAnswer {
        @Embedded …
Run Code Online (Sandbox Code Playgroud)

sqlite android android-room

15
推荐指数
1
解决办法
1555
查看次数

标签 统计

android ×1

android-room ×1

sqlite ×1