Describe the change of forceId
This commit is contained in:
parent
baa557116c
commit
ea13e95d9e
|
@ -154,3 +154,36 @@ var johndoe = new User({ name: 'John doe', age: 15, gender: 'm'});
|
||||||
```
|
```
|
||||||
|
|
||||||
See [related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/1084) here.
|
See [related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/1084) here.
|
||||||
|
|
||||||
|
## Users cannot provide a custom id value when id is auto-generated
|
||||||
|
|
||||||
|
For security reason, the default value of config variable `forceId` is set to
|
||||||
|
`true` if a model uses auto-generated id. It means creating/updating instance
|
||||||
|
with a given id will return an error message like:
|
||||||
|
|
||||||
|
```
|
||||||
|
Unhandled rejection ValidationError: The `MyModel` instance is not valid.
|
||||||
|
Details: `id` can't be set (value: 1).
|
||||||
|
```
|
||||||
|
|
||||||
|
You can change `forceId: false` in model.json file to disable the check, eg:
|
||||||
|
|
||||||
|
Change config in `common/models/MyModel.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "Product",
|
||||||
|
"forceId": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then create a new instance with given id:
|
||||||
|
|
||||||
|
```js
|
||||||
|
MyModel.create({
|
||||||
|
id: 1,
|
||||||
|
name: 'test',
|
||||||
|
}).then(function(modelInstance) {
|
||||||
|
// Get the modelInstance with id = 1.
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue