loopbackio / loopbackio/loopback-datasource-juggler
$inc is not working in embedded object loopback 3
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 282
- Forks
- 366
- Merge medio
- 17 h 4 min
- PR fusionados (30 d)
- 10
Descripción
I am using loopback 3. In which I have model Item and that have embedded object availableQtyBranchWise. I was trying to update the availableQtyBranchWise using $inc but with this operator i got validation error.
Item.json
{
"name": "Item",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true,
"strictObjectIDCoercion": true
},
"properties": {
"name": {
"type": "string"
},
"barcode": {
"type": "number"
}
},
"relations": {
"branchWiseAvailableQtyE": {
"type": "embedsMany",
"model": "BranchWiseAvailableQtyE",
"property": "branchWiseAvailableQty",
"options": {
"validate": false,
"forceId": true
},
"description": "branchWiseAvailableQtyE is used to store branch wise available quantity"
}
}
}
Branch Wise Available Qty Embedded Schema
{
"name": "BranchWiseAvailableQtyE",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"refBranchName": {
"type": "string",
"required": true
},
"refBranchId": {
"type": "string",
"required": true
},
"refBranchCode": {
"type": "string",
"required": true
},
"availableQty": {
"type": "number",
"required": true,
"default": 0
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
In DB Data should look like
{
"_id": {
"$oid": "66e90d94c2d97907244dfae0"
},
"name": "01 PlK 1 1000 SERIES",
"branchWiseAvailableQty": [
{
"refBranchName": "Delhi",
"refBranchId": {
"$oid": "6204c8d8e1300e2ea8420483"
},
"refBranchCode": "DL",
"availableQty": 20,
"id": {
"$oid": "f3ef503f555877c69cc8ed6a"
}
},
{
"refBranchName": "Mumbai",
"refBranchId": {
"$oid": "6204c8d8e1340e2ea8420483"
},
"refBranchCode": "MU",
"availableQty": 40,
"id": {
"$oid": "f3ef503f555987c69cc8ed6a"
}
}
],
"barcode": 1856
}
I was trying to increment, decrement availableQty when object exists and add object when does not exist.
This is my code where I update the availableQty
item.branchWiseAvailableQtyE.set(ObjectId(f3ef503f555987c69cc8ed6a),{ availableQty: {$inc: 10}}, null, function(err, result) {
if (err) {
return reject(err);
}
return resolve(result);
});
This give me validation error because I am using
{ availableQty: {$inc: 10}}
But If I use this syntax it works
{ availableQty: 10}
Please help me. Thanks, in advance
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Start with the Item.json embedsMany relation and the BranchWiseAvailableQtyE embedded schema, then reproduce the validation error at the branchWiseAvailableQtyE.set call using the shown $inc value. Trace how embedded-object updates are validated and determine whether incrementing availableQty and adding a missing object are supported; done means the supported behavior or required change is clearly established.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- database
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100