如何将用户表“ addressId”列与地址表“ id”列相关联? 和 当我插入用户模型数据时,如何在“用户和地址”两个表中插入数据。 和 提取数据时也一样?
地址模型是用户模型的嵌套类。
@Entity(tableName = "user")
public class User {
@PrimaryKey(autoGenerate = true)
private Integer localId;
private Integer id;
private String name;
private Integer addressId;
private Address address;
}
@Entity(tableName = "address")
public class Address {
@PrimaryKey(autoGenerate = true)
private Integer localId;
private Integer id;
private String address1;
private String address2;
private String address3;
}
答案 0 :(得分:0)
请参见https://developer.android.com/training/data-storage/room/referencing-data
基本上,您的选择是:
@Embedded