How to use Room Relation to get a list of another pojo

♀尐吖头ヾ 提交于 2019-12-11 22:25:11

问题


@Entity(tableName = "subscription")
data class Subscription(
    @PrimaryKey val planId: Int,
    @ColumnInfo(name = "plan_name") val planName: String? = null,
    @ColumnInfo(name = "plan_description") val planDescription: String? = null,
    @ColumnInfo(name = "plan_reg_fee") val planRegFee: String? = null,
    @ColumnInfo(name = "plan_monthly_charge") val planMonthlyCharge: String? = null
)


data class Benefit(
    @ColumnInfo(name = "benefit_id") val benefitId: Int? = null,
    @ColumnInfo(name = "benefit_code") val benefitCode: Int? = null,
    @ColumnInfo(name = "benefit_name") val benefitName: String? = null,
    @ColumnInfo(name = "benefit_status") val benefitStatus: String? = null
)

how to get a list of Benefit inside Subscription i.e.,

val benefitList: LiveData<List<Benefit>>? = null

using Room relation


回答1:


You can find examples from Google Documents. There are examples about Relation in Room.



来源:https://stackoverflow.com/questions/53183770/how-to-use-room-relation-to-get-a-list-of-another-pojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!