loopbackio / loopbackio/loopback-datasource-juggler

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

Offen
#1,968 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
JavaScript
Sterne
282
Forks
366
Ø Merge
17 Std. 4 Min.
Gemergte PRs (30 T.)
10

Beschreibung

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"
}

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei der Funktion createCallback in dao.js ungefähr bei Zeile 378 und verfolge, wie die Callback-ID dem erstellten Objekt zugewiesen wird. Reproduziere einen create-Aufruf mit einer ID von 0, füge anschließend eine Testabdeckung für die erwartete Antwort hinzu und überprüfe, dass IDs von 0 und höher beibehalten werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
55/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.