loopbackio / loopbackio/loopback-next
Loopback Connector Disregards Property Name
Nessuno ha ancora preso questa issue.
- 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
- 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- 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