{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/1340","repository_url":"https://api.github.com/repos/balderdashy/waterline","labels_url":"https://api.github.com/repos/balderdashy/waterline/issues/1340/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/waterline/issues/1340/comments","events_url":"https://api.github.com/repos/balderdashy/waterline/issues/1340/events","html_url":"https://github.com/balderdashy/waterline/pull/1340","id":147039140,"number":1340,"title":"[proposal] Added support for nested invalid attributes","user":{"login":"Zaggen","id":6466844,"avatar_url":"https://avatars.githubusercontent.com/u/6466844?v=3","gravatar_id":"","url":"https://api.github.com/users/Zaggen","html_url":"https://github.com/Zaggen","followers_url":"https://api.github.com/users/Zaggen/followers","following_url":"https://api.github.com/users/Zaggen/following{/other_user}","gists_url":"https://api.github.com/users/Zaggen/gists{/gist_id}","starred_url":"https://api.github.com/users/Zaggen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zaggen/subscriptions","organizations_url":"https://api.github.com/users/Zaggen/orgs","repos_url":"https://api.github.com/users/Zaggen/repos","events_url":"https://api.github.com/users/Zaggen/events{/privacy}","received_events_url":"https://api.github.com/users/Zaggen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/balderdashy/waterline/labels/Needs%20cleanup","name":"Needs cleanup","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-08T21:02:43Z","updated_at":"2016-04-08T21:05:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/balderdashy/waterline/pulls/1340","html_url":"https://github.com/balderdashy/waterline/pull/1340","diff_url":"https://github.com/balderdashy/waterline/pull/1340.diff","patch_url":"https://github.com/balderdashy/waterline/pull/1340.patch"},"body":"If you want to manually build an error based on `WLValidationError` that holds nested errors, because validation failed on nested data (association, nested documents, etc), there is no way to pass that data as invalidAttributes and get the expected result. There might not be support yet for deep validations but this opens the door for it. It's just a couple of simple helpers that iterate recursively if needed to properly normalize and format the errors.\r\n\r\nSo that this invalid attributes:\r\n\r\n```js\r\n{ location:\r\n      { country:\r\n         [ { rule: 'string',\r\n             message: '`undefined` should be a string (instead of \"null\", which is a object)' },\r\n           { rule: 'required',\r\n             message: '\"required\" validation rule failed for input: null' },\r\n           { rule: 'notEmpty',\r\n             message: '\"notEmpty\" validation rule failed for input: null' } ],\r\n        city:\r\n         [ { rule: 'string',\r\n             message: '`undefined` should be a string (instead of \"null\", which is a object)' },\r\n           { rule: 'in',\r\n             message: '\"in\" validation rule failed for input: null' },\r\n           { rule: 'required',\r\n             message: '\"required\" validation rule failed for input: null' },\r\n           { rule: 'notEmpty',\r\n             message: '\"notEmpty\" validation rule failed for input: null' } ],\r\n        }\r\n```\r\nCan keep that format (otherwise it gets modified) and we can get a nice error too, like this\r\n```\r\nError (E_VALIDATION)  ... some error details here\r\n• location:\r\n      • country:\r\n        • `undefined` should be a string (instead of \"null\", which is a object)\r\n        • \"required\" validation rule failed for input: null\r\n        • \"notEmpty\" validation rule failed for input: null\r\n      • city:\r\n        • `undefined` should be a string (instead of \"null\", which is a object)\r\n        • \"in\" validation rule failed for input: null\r\n        • \"required\" validation rule failed for input: null\r\n        • \"notEmpty\" validation rule failed for input: null\r\n```\r\n\r\nIf the use case is not clear, or something needs to be improved or modified let me know.\r\n\r\npst: Not sure if there are tests for this, i didn't check since i'm doing this for the project i'm currently working on, so if there are some tests that needs to be modified somehow, let me know that too."},"comment":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/comments/207606501","html_url":"https://github.com/balderdashy/waterline/pull/1340#issuecomment-207606501","issue_url":"https://api.github.com/repos/balderdashy/waterline/issues/1340","id":207606501,"user":{"login":"Zaggen","id":6466844,"avatar_url":"https://avatars.githubusercontent.com/u/6466844?v=3","gravatar_id":"","url":"https://api.github.com/users/Zaggen","html_url":"https://github.com/Zaggen","followers_url":"https://api.github.com/users/Zaggen/followers","following_url":"https://api.github.com/users/Zaggen/following{/other_user}","gists_url":"https://api.github.com/users/Zaggen/gists{/gist_id}","starred_url":"https://api.github.com/users/Zaggen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zaggen/subscriptions","organizations_url":"https://api.github.com/users/Zaggen/orgs","repos_url":"https://api.github.com/users/Zaggen/repos","events_url":"https://api.github.com/users/Zaggen/events{/privacy}","received_events_url":"https://api.github.com/users/Zaggen/received_events","type":"User","site_admin":false},"created_at":"2016-04-08T21:05:27Z","updated_at":"2016-04-08T21:05:27Z","body":"ok, fixed!"}}