[英]How to represent nested @Relation with Android Room?
Here is my POJO in kotlin: 这是我在Kotlin的POJO:
data class Pass(var uuid: String,
var activationRestrictions:List<ActivationRestriction>)
data class ActivationRestriction(var uuid: String,
var activationRestrictionExceptions:List<ActivationRestrictionException>)
data class ActivationRestrictionException(var uuid: String)
How can I represent this nested relation with Room? 如何用Room表示这种嵌套关系? Here is one of the solution, but it does not contain a nested relation.
这是解决方案之一,但它不包含嵌套关系。 I am specifically looking for solving a nested relationship with Room.
我特别在寻找解决与Room之间的嵌套关系的方法。
You can use @Relation
annotation for POJO classes. 您可以对POJO类使用
@Relation
批注。
A convenience annotation which can be used in a Pojo to automatically fetch relation entities.
一个方便注释,可以在Pojo中使用该注释自动获取关系实体。 When the Pojo is returned from a query, all of its relations are also fetched by Room.
当从查询返回Pojo时,Room还将获取其所有关系。
Here is the documentation. 这是文档。
Also, this answer has more details: Android Persistence room: "Cannot figure out how to read this field from a cursor" 另外,此答案还有更多详细信息: Android持久性室:“无法弄清楚如何从游标中读取此字段”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.