loopbackio / loopbackio/loopback-next

Empty relation should return empty array

オープン
#8,910 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

Describe the bug

Hi,

I'm migrating a project from loopback 3 to loopback 4 and I found inconsistencies between the two regarding relations.

I am querying a model which have a HasMany relation on another model like this:

export class User extends Entity {
 ...

  @hasMany(() => Order)
  orders: Order[];

 ...
}

The query looks like this:
/users?filter={"include": ["orders"]}

In the answer, I got an orders property for users that have orders but no orders property for users that don't. Here is an API response for example:

[
  ...
  {
    "id": "__",
    "email": "admin@example.com",
  },
  {
    "id": "__",
    "email": "support@example.com",
    "orders": [
      {...}
    ]
  },
  ...
]

Is this an intended behavior in loopback 4 ? I find this much harder to deal with undefined property instead of empty array when querying model with relation.

Best regards

Logs

No response

Additional information

No response

Reproduction

https://codesandbox.io/s/falling-frost-qn03xh?file=/src/models/user.model.ts

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Issue にリンクされている CodeSandbox の再現から始め、users のレスポンスで include された HasMany リレーションがどのように表現されるかを確認します。orders がある場合とない場合の users を比較し、その後 include の処理を追って、期待されるレスポンスの形を特定します。データが入っているリレーションと空のリレーションの両方について、動作が定義され、カバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
api, backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

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

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