loopbackio / loopbackio/loopback-next

Loopback Connector Disregards Property Name

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

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

developer-experience good first issue help wanted Juggler
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

Description / Steps to reproduce / Feature proposal

The @ property decorator has a name property which should specify the column name in the database in case it does not match with the field name in your model. However, the code in loopback-connector/sql.js does not utilize this metada so you only get the field name as it's defined in your model. In my case, I am using DB2 and this causes issues because the generated SQL select statement uses double-quotes around each field signify to DB2 that the field name matches exactly with what is specified in the DB (i.e. case sensitive).

To Reproduce:
Create a DB2 database w

  1. ith a table "DRIVER" that contains field "DRIVER_ID".
  2. Setup a basic Loopback4 project like the Todo Tutorial (replacing instances of Todo with Driver) but use a DB2 based datasource.
  3. Create the Model like the following:
@model({
  name: 'DRIVER',   // This corrects the case-sensitive issue at the Table level.
  }
})
export class Driver extends Entity {
  @property({
    name: 'DRIVER_ID', // This is ignored by field mapping functions.
    type: 'number',
    id: true,
  })
  fooId?: number;
  1. Use VS Code to start the server in Debug and issue a GET against drivers
  2. In the sql.js --> buildColumnNames note that the name is 'fooId' instead of 'DRIVER_ID'
  3. Continue execution, you will receive an SQL0206N error from DB2: "fooId" is not valid in the context where it used.

Current Behavior

sql.js simply uses the field names as the DB column names.

Expected Behavior

sql.js should map to the @ property 'name' property to determine the correct column names.

Connectors to fix

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

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

はじめの一歩

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

調査の方向性

loopback-connector/sql.js の buildColumnNames から始め、フィールド名の処理を、再現手順に示されているプロパティ名のメタデータと比較してください。この issue を変更する前に、参照されている SQL connector の変更を確認してください。生成された SELECT 列が fooId プロパティに対して DRIVER_ID を使用し、DB2 の再現で SQL0206N が発生しなくなれば完了です。

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

評価

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

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

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