How to create a table with a two or more foreign keys using Android Room?

前端 未结 2 1985
孤独总比滥情好
孤独总比滥情好 2020-12-31 09:34

According the entity-relationship model, the relationship between tbl_post and tbl_category could be specified using Room Persistency Libr

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 09:48

    In Kotlin:

    @Entity(
        tableName = "some_table",
        indices = [Index("id"), Index("brand_id"), Index("model_id")],
        foreignKeys = [
            ForeignKey(entity = BrandEntity::class, parentColumns = ["id"],
                childColumns = ["brand_id"]),
            ForeignKey(entity = ModelEntity::class, parentColumns = ["id"],
                childColumns = ["model_id"]),
            ForeignKey(entity = Table1Entity::class, parentColumns = ["id"],
                childColumns = ["table1_id"]),
            ForeignKey(entity = Table2Entity::class, parentColumns = ["id"],
                childColumns = ["table2_id"])
        ]
    )
    

提交回复
热议问题