loopbackio / loopbackio/loopback-datasource-juggler

[BUG] create helper function ignores the id property when it's equal to 0.

Aperta
#1,968 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
JavaScript
Stelle
282
Fork
366
Merge medio
17h 4m
PR unite (30g)
10

Descrizione

**Description** :
Create call on a loopback model returns a property id as a response, in case where the property id starts from 0 it is removed from response. This is because the create function( dao.js line no 378) which gets the id as a callback on the create call in a loopback model, does not accepts 0 as an id.

Code snippet from dao.js
if id is 0 it is skipping the if block
```
function createCallback(err, id, rev) {
if (id) {
obj.__data[_idName] = id;
defineReadonlyProp(obj, _idName, id);
}
````
We have a scenario where the id starts from 0, and this is causing the id property for our 0th element to be removed from the response.

Steps to reproduce :
* Model which has a property id which starts from 0.
* Call the api to create which will have the id (starting from 0) in response.
* Response will be missing the id property for the first call where id is 0, and it'll add the id property in response starting from id as 1 onwards.

Current Response Behaviour :
id is removed when its value is equal to 0

```
{
"property1" : "property1",
"property2" : "property2"
}

```

Expected Results :

```
{
"id" : 0
"property1" : "property1",
"property2" : "property2"
}

```

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 dalla funzione createCallback in dao.js, intorno alla riga 378, e segui come l’id del callback viene assegnato all’oggetto creato. Riproduci una chiamata create con un id pari a 0, quindi aggiungi la copertura per la risposta prevista e verifica che gli id pari o superiori a 0 vengano preservati.

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

Valutazione

Stack tecnologico
javascript
Ambito
databases
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.