agrosner / agrosner/DBFlow

How to load list of objects with related objects (annotated with ForeignKey)?

オープン
#1,725 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Kotlin
スター
4.8k
フォーク
593
平均マージ
1分
マージ済み PR(30日)
1

説明

DBFlow Version: 4.2.4

Bug or Feature Request: /

Description:

How to load list of objects with related objects (annotated with ForeignKey)?

Code example:
```
@Table(database = Database::class)
class A : BaseModel() {
@Column @PrimaryKey var id: Int = 0
@Column var name = ""
@Column @ForeignKey(onDelete = ForeignKeyAction.RESTRICT, saveForeignKeyModel = true)
var b: B? = null
}
```
```
@Table(database = Database::class)
class B : BaseModel() {
@Column @PrimaryKey var id: Int = 0
@Column var name = ""
}
```

I need to load list of A objects populated with B object. When I load 100 objects of class A and then iterate on them one by one and access B through them, DBFlow fires 100 SELECT queries. I wish to somehow load B's together with A's in a single query, and then populate A's with B's so no further queries are fired. So I was expecting that if query has INNER JOIN that it will automatically populate A object with B objects. Executed query:

```
SELECT DISTINCT `a`.`id`,`a`.`name`,`b`.`id`,`b`.`name` FROM `A` AS `a` INNER JOIN `B` AS `b` ON `a`.`b_id`=`b`.`id`
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。