$inc is not working in embedded object loopback 3

未关闭
#2,319 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
javascript
领域
database

调研方向

从 Item.json 中的 embedsMany 关系和嵌入式 schema BranchWiseAvailableQtyE 开始,然后使用所示的 $inc 值,在调用 branchWiseAvailableQtyE.set 时重现验证错误。跟踪嵌入式对象更新的验证方式,并确定是否支持递增 availableQty 以及添加缺失的对象;当支持的行为或所需的更改得到明确确立时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

bug

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

But If I use this syntax it works

{ availableQty: 10}

Please help me. Thanks, in advance

主要语言
JavaScript
星标
279
派生
362
平均合并
21 小时 14 分钟
30 天内合并 PR
16

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

loopbackio/loopback-datasource-juggler 的其他 Issue

查看 loopbackio/loopback-datasource-juggler 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。