loopbackio / loopbackio/loopback-next

Loopback Connector Disregards Property Name

Aperta
#1,837 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

developer-experience good first issue help wanted Juggler
Lingua principale
TypeScript
Stelle
5.1k
Fork
1.1k
Merge medio
2g 21h
PR unite (30g)
27

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in loopback-connector/sql.js, in buildColumnNames, e confronta la gestione dei nomi dei campi con i metadati del nome della proprietà mostrati nella riproduzione. Controlla la modifica referenziata del connettore SQL prima di modificare questa issue. Il lavoro è completato quando le colonne SELECT generate usano DRIVER_ID per la proprietà fooId e la riproduzione DB2 non genera più SQL0206N.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
database
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.