Skip to content

Commit 2ee331e

Browse files
authored
Merge pull request #1103 from strongloop/doc/forceId-3.x
Describe the change of forceId
2 parents baa5571 + ea13e95 commit 2ee331e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

3.0-RELEASE-NOTES.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,36 @@ var johndoe = new User({ name: 'John doe', age: 15, gender: 'm'});
154154
```
155155

156156
See [related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/1084) here.
157+
158+
## Users cannot provide a custom id value when id is auto-generated
159+
160+
For security reason, the default value of config variable `forceId` is set to
161+
`true` if a model uses auto-generated id. It means creating/updating instance
162+
with a given id will return an error message like:
163+
164+
```
165+
Unhandled rejection ValidationError: The `MyModel` instance is not valid.
166+
Details: `id` can't be set (value: 1).
167+
```
168+
169+
You can change `forceId: false` in model.json file to disable the check, eg:
170+
171+
Change config in `common/models/MyModel.json`:
172+
173+
```json
174+
{
175+
"name": "Product",
176+
"forceId": false
177+
}
178+
```
179+
180+
Then create a new instance with given id:
181+
182+
```js
183+
MyModel.create({
184+
id: 1,
185+
name: 'test',
186+
}).then(function(modelInstance) {
187+
// Get the modelInstance with id = 1.
188+
});
189+
```

0 commit comments

Comments
 (0)