loopbackio / loopbackio/loopback-next

Polymorphic Relation - Wrong Doc

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

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

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

説明

Describe the bug

Hi there!

Let's suppose a base Delivery model with 3 fields: id, deliverableType, and deliverableId.
If you follow the docs, you'll get this error when requesting some deliverable relations:

Request GET /deliveries?filter=whatever failed with status code 500. Error: ER_BAD_FIELD_ERROR: Unknown column 'deliverable' in 'field list'

This is caused by this part of code, as you're asking it to search on the corresponding datasource for the field "deliverable" which doesn't exist:

class Delivery extends Entity {
@hasOne(() => Deliverable, {polymorphic: true})
  deliverable: Deliverable;

deliverableType: string;
}

Instead, it should be like this (search deliverableId on deliverableType's model):

class Delivery extends Entity {
@hasOne(() => Deliverable, {polymorphic: true})
  deliverableId: string;

deliverableType: string;
id: string;
}

With that change, polymorphic relation is working as expected (assuming repositories are correctly configured)

Logs

No response

Additional information

No response

Reproduction

Not needed

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

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

はじめの一歩

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

調査の方向性

https://loopback.io/doc/en/lb4/Polymorphic-relation.html の Polymorphic relation ドキュメントから始め、そこにある Delivery の例を issue で報告されたフィールドと比較します。関係が deliverableId と deliverableType を使用するように例を更新し、ドキュメント化された例が存在しない deliverable フィールドを要求しなくなったことを確認します。

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

評価

技術スタック
typescript
領域
documentation
issue の種類
ドキュメント
難易度
1/5
見積もり時間
1時間未満
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

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

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