{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/586","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/586/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/586/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/586/events","html_url":"https://github.com/strongloop/loopback/issues/586","id":43921339,"number":586,"title":"No validation occuring when updating (PUT) a document with the ID as a string","user":{"login":"SumeetR","id":6136978,"avatar_url":"https://avatars.githubusercontent.com/u/6136978?v=3","gravatar_id":"","url":"https://api.github.com/users/SumeetR","html_url":"https://github.com/SumeetR","followers_url":"https://api.github.com/users/SumeetR/followers","following_url":"https://api.github.com/users/SumeetR/following{/other_user}","gists_url":"https://api.github.com/users/SumeetR/gists{/gist_id}","starred_url":"https://api.github.com/users/SumeetR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SumeetR/subscriptions","organizations_url":"https://api.github.com/users/SumeetR/orgs","repos_url":"https://api.github.com/users/SumeetR/repos","events_url":"https://api.github.com/users/SumeetR/events{/privacy}","received_events_url":"https://api.github.com/users/SumeetR/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2014-09-25T13:51:55Z","updated_at":"2015-03-24T22:13:50Z","closed_at":null,"body":"Hi,\r\n\r\nI have discovered an issue when using the PUT method to update a record. We are using mongodb as the database and communicating with it through Loopback 2.0.\r\n\r\nWe have a model called Activity and its .json file looks like this, please note that both properties are set to required:\r\n\r\n```\r\n{\r\n  \"name\": \"Activities\",\r\n  \"strict\": true,\r\n  \"options\": {\r\n    \"idInjection\": true\r\n  },\r\n  \"properties\": {\r\n    \"name\": {\r\n      \"type\": \"string\",\r\n      \"required\": true\r\n    },\r\n    \"type\": {\r\n      \"type\": \"string\",\r\n      \"required\": true\r\n  },\r\n  \"validations\": [],\r\n  \"relations\": {},\r\n  \"acls\": [],\r\n  \"methods\": []\r\n}\r\n``` \r\n\r\nWhen I GET an object from the server, it returns the following object:\r\n\r\n``` \r\n{\r\n   id: \"5420902b5bab5bf00fd6339b\",  \r\n   name: \"Joao\", \r\n   type: \"activityA\"\r\n}\r\n``` \r\n\r\nNow if I update this object, deleting the name or type field (so they are blank or null) and send it back to the server, I get a 200 OK response and the data has been correctly updated, even though the strings are in blank or null.\r\n\r\nI tested this on the Loopback explorer and found out that the issue is due to the formatting of the ID field. \r\n\r\nSo, the first test I did, the data looked like this at first, with the ID as an object (mimicking what the explorer shows as 'model schema'):\r\n\r\n``` \r\n{\r\n  \"name\": \"\",\r\n  \"type\": \"activityA\",\r\n    \"_id\": {\r\n        \"$oid\": \"5420902b5bab5bf00fd6339b\"\r\n    }\r\n}\r\n``` \r\n\r\nThis returns a 422 Validation Error message notifying that the name field cannot be blank. But, if I format the data as follows, I am able to carry out the PUT method. Notice the difference in the ID field, which is now a string:\r\n\r\n``` \r\n{\r\n  \"name\": \"\",\r\n  \"type\": \"activityA\",\r\n  \"id\": \"5420902b5bab5bf00fd6339b\"\r\n}\r\n``` \r\n\r\nThe above returns a 200 OK message and checking the database, the record has been updated with an empty string for name. \r\n\r\nThis is strange as the object above (ID as string) is exactly how data is returned by the server when carrying out a GET method, thus updating this returned object seems to bypass the validation if the ID is formatted as a string rather than an object. \r\n\r\nCan someone please advise how to proceed with this? Is there something wrong in the model definition or is it a loopback issue? Please note that this does not occur when creating a new document, only when updating an existing one (hence the attention given to ID formatting).\r\n\r\nThank you for your time,\r\nSumeet"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/85713826","html_url":"https://github.com/strongloop/loopback/issues/586#issuecomment-85713826","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/586","id":85713826,"user":{"login":"shlomiassaf","id":5377501,"avatar_url":"https://avatars.githubusercontent.com/u/5377501?v=3","gravatar_id":"","url":"https://api.github.com/users/shlomiassaf","html_url":"https://github.com/shlomiassaf","followers_url":"https://api.github.com/users/shlomiassaf/followers","following_url":"https://api.github.com/users/shlomiassaf/following{/other_user}","gists_url":"https://api.github.com/users/shlomiassaf/gists{/gist_id}","starred_url":"https://api.github.com/users/shlomiassaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shlomiassaf/subscriptions","organizations_url":"https://api.github.com/users/shlomiassaf/orgs","repos_url":"https://api.github.com/users/shlomiassaf/repos","events_url":"https://api.github.com/users/shlomiassaf/events{/privacy}","received_events_url":"https://api.github.com/users/shlomiassaf/received_events","type":"User","site_admin":false},"created_at":"2015-03-24T22:13:49Z","updated_at":"2015-03-24T22:13:49Z","body":":+1: "}}