loopbackio / loopbackio/loopback-datasource-juggler

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

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

还没有人认领这个 Issue。

bug
主要语言
JavaScript
星标
282
派生
366
平均合并
17 小时 4 分钟
30 天内合并 PR
10

描述

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

```

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 dao.js 第 378 行附近的 createCallback 函数开始,跟踪 callback id 是如何分配给已创建对象的。复现一次 id 为 0 的 create 调用,然后为预期响应添加覆盖率,并验证 0 及更大的 id 都会被保留。

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

评估

技术栈
javascript
领域
databases
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 发到你的邮箱

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