我对Room数据库的工作方式有了新的认识,并且想知道如何查询以下内容。
查询基于其中包含嵌入对象的对象 在嵌入对象上。
查询包含外键的对象
@Entity
@Entity
public class Car {
@PrimaryKey()
private String id;
@Embedded()
private Engine engine
@Ignore
private List<Tire> tires
... //relevant getters and setters
}
public class Engine {
private String id;
private String type;
private String name;
}
@Entity(foreignKeys = {@ForeignKey(
entity = Car.class, parentColumn = "id", childColumn ="carIdFk")
}
public class Tire {
@PrimaryKey(autogenerated=true)
private int id;
private String model;
private String rimModel;
private String cardIdFk;
}
@Dao
public interface CarDao {
//Need a query to retrieve all cars where engine id == <somevalue>
//Need a query to retrieve all cars where tire model == <somevalue>
}
@Dao
public interface TyreDao {
//Need a query to retrieve all cars where tire id == <somevalue>
}