loopbackio / loopbackio/loopback-datasource-juggler

$inc is not working in embedded object loopback 3

オープン
#2,319 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
JavaScript
スター
282
フォーク
366
平均マージ
17時間 4分
マージ済み PR(30日)
10

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず Item.json の embedsMany リレーションと埋め込みスキーマ BranchWiseAvailableQtyE を確認し、次に、示されている $inc 値を使った branchWiseAvailableQtyE.set 呼び出しでバリデーションエラーを再現します。埋め込みオブジェクトの更新がどのように検証されるかを追跡し、availableQty のインクリメントと不足しているオブジェクトの追加がサポートされているかを判断します。サポートされる動作または必要な変更が明確に確立されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
database
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。