TblCategory.java
@Entity
class TblCategory {
@PrimaryKey
@ColumnInfo(name="cat_id")
public String id;
@ColumnInfo(name = "cat_name")
public String name;
}
TblPost.java (外部キー参照が欠落していますが、この場合は重要ではありません)
@Entity
class TblPost {
@PrimaryKey
@ColumnInfo(name="post_id")
public String id;
public String title, content, create_time, author_id;
}
TblPostCategory.java
@Entity(foreignKeys = {
@ForeignKey(
entity = TblPost.class,
parentColumns = "post_id",
childColumns = "tbl_post_id"
),
@ForeignKey(
entity = TblCategory.class,
parentColumns = "cat_id",
childColumns = "tbl_category_id"
)
})
class TblPostCategory {
@PrimaryKey
@ColumnInfo(name="tbl_post_id")
public String id;
@ColumnInfo(name = "tbl_category_id")
public String categoryId;
}