loopbackio / loopbackio/loopback-datasource-juggler
[BUG] create helper function ignores the id property when it's equal to 0.
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 282
- Forks
- 366
- Merge moyen
- 17 h 4 min
- PR mergées (30 j)
- 10
Description
**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"
}
```
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la fonction createCallback dans dao.js, vers la ligne 378, et suivez la manière dont l’identifiant du callback est attribué à l’objet créé. Reproduisez un appel create avec un identifiant égal à 0, puis ajoutez une couverture pour la réponse attendue et vérifiez que les identifiants supérieurs ou égaux à 0 sont conservés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- databases
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 55/100