From ea13e95d9efe4326b60e2aedff42f5ddd7c35730 Mon Sep 17 00:00:00 2001 From: jannyHou Date: Tue, 20 Sep 2016 14:15:33 -0400 Subject: [PATCH] Describe the change of forceId --- 3.0-RELEASE-NOTES.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/3.0-RELEASE-NOTES.md b/3.0-RELEASE-NOTES.md index cbbef11f..9455f9ae 100644 --- a/3.0-RELEASE-NOTES.md +++ b/3.0-RELEASE-NOTES.md @@ -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. + +## 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. +}); +```