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

未關閉
#1,968 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
javascript
領域
databases

研究方向

從 dao.js 第 378 行附近的 createCallback 函式開始,追蹤 callback id 如何指派給已建立的物件。重現一次 id 為 0 的 create 呼叫,然後為預期回應新增涵蓋範圍,並驗證 0 及更大的 id 都會被保留。

由索引模型根據 Issue 內容生成。

描述

bug

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

主要語言
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 摘要。