loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Add model strict property to Troubleshooting / FAQ or other xrefs

Open bluestaralone opened this issue 12 years ago • 12 comments

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 ?

bluestaralone avatar Oct 09 '14 04:10 bluestaralone

+1

I got the same issue!

projectxmaker avatar Oct 09 '14 14:10 projectxmaker

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

raymondfeng avatar Oct 09 '14 16:10 raymondfeng

my problem is solved.

thanks :)

projectxmaker avatar Oct 10 '14 08:10 projectxmaker

@crandmck perhaps we could document this in "FAQ" or "Troubleshooting" or a similar section of our docs?

bajtos avatar Oct 15 '14 15:10 bajtos

Reopening as docs issue.

crandmck avatar Oct 20 '14 20:10 crandmck

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.

crandmck avatar Oct 24 '14 23:10 crandmck

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.

crandmck avatar Oct 27 '14 18:10 crandmck

@raymondfeng "Strict: true" work perfectly in create mode but in edit mode it doesn't work, please tell me why ?

bluestaralone avatar Nov 05 '14 04:11 bluestaralone

@bluestaralone please open a new GH issue and describe steps to reproduce the problem.

bajtos avatar Nov 05 '14 08:11 bajtos

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 avatar Jul 23 '15 06:07 cookejames

@cookejames see: https://github.com/strongloop/loopback-datasource-juggler/pull/666

fabien avatar Jul 23 '15 06:07 fabien

@fabien thanks for the pull request - looks like you've just done exactly what I did

cookejames avatar Jul 23 '15 07:07 cookejames