Add model strict property to Troubleshooting / FAQ or other xrefs
I don't know why we don't prevent user set informations which are not defined in Model.json.
Ex: When i create Book model with properties are "name" and "description" but when i request POST method to create Book i provide informations like below:
{
"name":"Book 1",
"description":"This is a book 1",
"abcdef":"This is other information which is not defined in Model.json"
}
=> As you can see that "abcdef" is not defined in Book.json but it still be inserted to "Book" collection of mongodb. Please tell me how to prevent it if it not a bug ?
+1
I got the same issue!
Models can be configured with a strict mode in the options:
strict: false (by default for NoSQL) strict: true (by default for SQL) ignore unknown properties strict: "throw" will throw if unknown properties are used
my problem is solved.
thanks :)
@crandmck perhaps we could document this in "FAQ" or "Troubleshooting" or a similar section of our docs?
Reopening as docs issue.
I added this to http://docs.strongloop.com/display/LB/Customizing+models#Customizingmodels-Customzingothermodelsettings. Right now, we don't have a FAQ or Troubleshooting for LB. Perhaps we should, but that's for another issue IMO.
Raymond, do you think this is sufficient for now? PTAL at above doc and revise / comment, then either close or assign back to me. ty.
@raymondfeng "Strict: true" work perfectly in create mode but in edit mode it doesn't work, please tell me why ?
@bluestaralone please open a new GH issue and describe steps to reproduce the problem.
Its very annoying that this works in creation but not update - I've had to create a boot script that intercepts updates and removes properties not defined on the model from the request.
@cookejames see: https://github.com/strongloop/loopback-datasource-juggler/pull/666
@fabien thanks for the pull request - looks like you've just done exactly what I did