loopbackio / loopbackio/loopback-next
Loopback Connector Disregards Property Name
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 5.1k
- Forks
- 1.1k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 27
Beschreibung
## 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:
```typescript
@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;
```
4. Use VS Code to start the server in Debug and issue a GET against drivers
5. In the sql.js --> buildColumnNames note that the name is 'fooId' instead of 'DRIVER_ID'
6. 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
- [x] 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in loopback-connector/sql.js bei buildColumnNames und vergleiche die Behandlung von Feldnamen mit den in der Reproduktion angezeigten Metadaten zum Eigenschaftsnamen. Prüfe die referenzierte Änderung am SQL-Connector, bevor du dieses Issue änderst. Fertig ist die Änderung, wenn generierte SELECT-Spalten für die Eigenschaft fooId DRIVER_ID verwenden und die DB2-Reproduktion keinen SQL0206N-Fehler mehr auslöst.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- database
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100