{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/759","labels_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/759/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/759/comments","events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/759/events","html_url":"https://github.com/strongloop/loopback-datasource-juggler/issues/759","id":116318307,"number":759,"title":"updateAttributes on model calls validation for other fields","user":{"login":"ekussberg","id":5912520,"avatar_url":"https://avatars.githubusercontent.com/u/5912520?v=3","gravatar_id":"","url":"https://api.github.com/users/ekussberg","html_url":"https://github.com/ekussberg","followers_url":"https://api.github.com/users/ekussberg/followers","following_url":"https://api.github.com/users/ekussberg/following{/other_user}","gists_url":"https://api.github.com/users/ekussberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ekussberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ekussberg/subscriptions","organizations_url":"https://api.github.com/users/ekussberg/orgs","repos_url":"https://api.github.com/users/ekussberg/repos","events_url":"https://api.github.com/users/ekussberg/events{/privacy}","received_events_url":"https://api.github.com/users/ekussberg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-11T11:49:10Z","updated_at":"2015-12-14T11:41:11Z","closed_at":null,"body":"Hello,\r\n\r\nwe have noticed a problem, that when we use the update of specific fields and before that we queried data with \"fields:{...}\" it is throwing validation errors for other fields, that are out of the update scope. For example:\r\n\r\nRequired: title, description\r\nQuery: fields{title:true}\r\nUpdate: title: \"aaa\"\r\nError: description is required\r\n\r\nThis should be fixed to validate only the attributes, that are the part of update scope?\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/comments/164416681","html_url":"https://github.com/strongloop/loopback-datasource-juggler/issues/759#issuecomment-164416681","issue_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/759","id":164416681,"user":{"login":"florianheinze","id":3868517,"avatar_url":"https://avatars.githubusercontent.com/u/3868517?v=3","gravatar_id":"","url":"https://api.github.com/users/florianheinze","html_url":"https://github.com/florianheinze","followers_url":"https://api.github.com/users/florianheinze/followers","following_url":"https://api.github.com/users/florianheinze/following{/other_user}","gists_url":"https://api.github.com/users/florianheinze/gists{/gist_id}","starred_url":"https://api.github.com/users/florianheinze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/florianheinze/subscriptions","organizations_url":"https://api.github.com/users/florianheinze/orgs","repos_url":"https://api.github.com/users/florianheinze/repos","events_url":"https://api.github.com/users/florianheinze/events{/privacy}","received_events_url":"https://api.github.com/users/florianheinze/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T11:41:11Z","updated_at":"2015-12-14T11:41:11Z","body":"I experience the same. I had to create (or better extend) a dirty workaround:\r\n\r\n    // in common/models/my-model.js\r\n    MyModel.observe('before save', function(ctx, next) {\r\n\r\n      // TODO this is another ugly workaround to trigger validation also for updates\r\n      // i expect this is a bug: https://github.com/strongloop/loopback-datasource-juggler/issues/771\r\n      if (ctx.data) {\r\n        var d = new MyModel(ctx.data);\r\n        d.isValid(function (valid) {\r\n          if (valid) {\r\n            next();\r\n          } else {\r\n            // TODO dirty workaround to detect if an unmodified field is claimed as invalid\r\n            // https://github.com/strongloop/loopback-datasource-juggler/issues/759\r\n            for (var k in ctx.data) {\r\n              if (d.errors[k]) {\r\n                next(d.errors);\r\n                return;\r\n              }\r\n            }\r\n            next();\r\n          }\r\n        }); // is valid function\r\n      } else {\r\n        next();\r\n      }\r\n\r\n    });\r\n\r\nNote that there are actually two workarounds. There seems to be another scary bug that the validation isn't triggered at all for (some?) updates (https://github.com/strongloop/loopback-datasource-juggler/issues/771). I am not sure if that workaround is necessary for this bug.\r\n\r\nMaybe it helps someone."}}