房间中的嵌套关​​系

时间:2018-10-20 16:58:11

标签: android android-room android-architecture-components

我有实体:

@Entity
public class Item {
    @PrimaryKey(autoGenerate = true)
    public long id;
    public String value;
}

@Entity
public class Image {
    @PrimaryKey(autoGenerate = true)
    public long id;
    public String value;
    public long patternId;
    public long itemId;
}

@Entity
public class Pattern {
    @PrimaryKey(autoGenerate = true)
    public long id;
    public String value;
}

与关系:

public class ItemWithImages {
    @Embedded
    public Item item;

    @Relation(parentColumn = "id", entityColumn = "itemId")
    public List<ImageWithPattern> imageWithPattern;
}

public class ImageWithPattern {
    @Embedded
    public Image image;

    @Embedded
    public Pattern pattern;
}

Dao查询:

Query("SELECT * FROM items LEFT JOIN patterns ON images.patternId = patterns.id")
public abstract Maybe<List<ItemWithImages>> getItems();

这是我的错误:

  

查询存在问题:[SQLITE_ERROR] SQL错误或丢失   数据库(无此类列:images.pattern_id)

0 个答案:

没有答案