loopbackio / loopbackio/loopback-next
Loopback Connector Disregards Property Name
まだ誰も着手していません。
- 主要言語
- 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
- ith a table "DRIVER" that contains field "DRIVER_ID".
- Setup a basic Loopback4 project like the Todo Tutorial (replacing instances of Todo with Driver) but use a DB2 based datasource.
- 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;
- Use VS Code to start the server in Debug and issue a GET against drivers
- In the sql.js --> buildColumnNames note that the name is 'fooId' instead of 'DRIVER_ID'
- 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
- SQL connectors - done by strongloop/loopback-connector#142
- MongoDB https://github.com/strongloop/loopback-connector-mongodb
- CouchDB2 https://github.com/strongloop/loopback-connector-couchdb2
- Cloudant https://github.com/strongloop/loopback-connector-cloudant (may depend on couchdb2)
- Cassandra https://github.com/strongloop/loopback-connector-cassandra
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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