查询嵌入式元素& Android Room中的外键元素

时间:2017-12-14 11:59:32

标签: java android mysql android-room

我对Room数据库的工作方式有了新的认识,并且想知道如何查询以下内容。

  1. 查询基于其中包含嵌入对象的对象 在嵌入对象上。

  2. 查询包含外键的对象

  3. @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>
    }
    

0 个答案:

没有答案