Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[@loopback/sequelize] Duplicate column names in relation queries

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

メンテナーはふだん 2 日以内に返信

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

評価

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

調査の方向性

Sequelize の拡張テストと、コミット 3c29d852b46f19f4805d556ae32aee49c79471f1 の再現用の変更から始めてください。クエリが Sequelize に到達する前の Patient リレーションの設定と、keyFrom、keyTo、through の処理を調査してください。すべてのプロパティが明示的に設定されていないリレーションで重複したカラムが生成されなくなり、拡張テストにリグレッションカバレッジが含まれていれば完了です。

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

説明

bug sequelize
Describe the bug

Repository queries with relations that do not explicitly set all the keyTo / keyFrom / through properties will lead to broken SQL queries that contain duplicated title case column names mixed in with the expected camelcase columns.

Example:

SELECT bookid as bookId, reader.id as readerId, ReaderId …

Relates to:
https://github.com/sequelize/sequelize/issues/9328
https://github.com/loopbackio/loopback-next/issues/9591
https://github.com/sourcefuse/loopback4-sequelize/issues/35

Logs

No response

Additional information

Workaround seems to be to go through all the Entity relations and explicitly set all the relation key names but that can be time-consuming and error-prone with a larger project. It seems like it might be possible to mitigate this at the loopback model to Sequelize relation layer.

Reproduction

With these changes, running the tests for the Sequelize extension will replicate the error:
https://github.com/KalleV/loopback-next/commit/3c29d852b46f19f4805d556ae32aee49c79471f1

Turns out it's necessary to define additional "belongsTo" relations in other entities before this happens. The extra relation is added to the "Patient" entity in this case. With this set up, I am seeing the following happen:

  • The default relation properties are set by Loopback (i.e. I can see the "keyFrom" is populated as todoListId) but the "keyTo" is undefined:
    loopback_relation_data
  • This leads to undefined being passed as the foreign key to sequelize:
    undefined_foreign_key
  • And then that causes Sequelize to assign a Title Case property through it's own default relation column logic leading to a duplicate column name in the database query:
    duplicate_column_sqlite_error
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
4日 22時間
マージ済み PR(30日)
31

環境構築

はじめの一歩

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

loopbackio/loopback-next のほかの issue

loopbackio/loopback-next の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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