gpt4 book ai didi

安卓机房 : How to model relationships?

转载 作者:IT老高 更新时间:2023-10-28 22:14:46 26 4
gpt4 key购买 nike

我刚刚开始使用 Room,尽管一切似乎都非常直观,但我目前并不真正了解我该如何处理人际关系。

Because SQLite is a relational database, you can specify relationships between objects. Even though most ORM libraries allow entity objects to reference each other, Room explicitly forbids this. Even though you cannot use direct relationships, Room still allows you to define Foreign Key constraints between entities.(Source: https://developer.android.com/topic/libraries/architecture/room.html#no-object-references)

  1. 您应该如何模拟多对多一对多关系?
  2. 这在实践中会是什么样子(例如 DAO + 实体)?

最佳答案

您可以使用 @Relation 注释来处理 Room 中的关系。

A convenience annotation which can be used in a Pojo to automatically fetch relation entities. When the Pojo is returned from a query, all of its relations are also fetched by Room.

See document.

(谷歌的文档有令人困惑的例子。我在另一个答案中写了步骤和一些基本解释。你可以check it out)

关于安卓机房 : How to model relationships?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44069878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com