{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/488","labels_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/488/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/488/comments","events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/488/events","html_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/488","id":59983879,"number":488,"title":"Improve instance-level operation hooks","user":{"login":"fabien","id":2749,"avatar_url":"https://avatars.githubusercontent.com/u/2749?v=3","gravatar_id":"","url":"https://api.github.com/users/fabien","html_url":"https://github.com/fabien","followers_url":"https://api.github.com/users/fabien/followers","following_url":"https://api.github.com/users/fabien/following{/other_user}","gists_url":"https://api.github.com/users/fabien/gists{/gist_id}","starred_url":"https://api.github.com/users/fabien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabien/subscriptions","organizations_url":"https://api.github.com/users/fabien/orgs","repos_url":"https://api.github.com/users/fabien/repos","events_url":"https://api.github.com/users/fabien/events{/privacy}","received_events_url":"https://api.github.com/users/fabien/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels/%23review","name":"#review","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":83,"created_at":"2015-03-05T17:17:28Z","updated_at":"2015-03-06T21:18:03Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/488","html_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/488","diff_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/488.diff","patch_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/488.patch"},"body":"For consistency, all instance-level operations (`prototype.updateAttributes` and `prototype.delete`) will now have access to the current instance as part of the hook's `context`:\r\n\r\n- `prototype.save` + `before save`:  the instance will be available as `instance` (unchanged behavior).\r\n\r\n- `prototype.save` + `after save`:  the instance will be available as `instance` (unchanged behavior).\r\n\r\n- `prototype.updateAttributes` + `before save`: because the instance should not be manipulated directly, the instance will be available as **currentInstance** to distinguish between the `instance` that *can* be directly modified (it is omitted now). In other words, `currentInstance` provides the current 'state' of the instance, and it should be regarded as immutable. Any modifications should be applied to `context.data`, which incorporates the partial nature of the `updateAttributes` operation.\r\n\r\n- `prototype.updateAttributes` + `after save`: in *after* hooks, this difference is not important, and thus, the instance will be simply be available as `instance`.\r\n\r\n- `prototype.remove/destroy/delete` + `before save`: again, the difference is irrelevant, so the instance will be available as `instance`.\r\n\r\n- `prototype.remove/destroy/delete` + `after save`:  the instance will be available as `instance`."},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/comments/77637545","html_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/488#issuecomment-77637545","issue_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/488","id":77637545,"user":{"login":"fabien","id":2749,"avatar_url":"https://avatars.githubusercontent.com/u/2749?v=3","gravatar_id":"","url":"https://api.github.com/users/fabien","html_url":"https://github.com/fabien","followers_url":"https://api.github.com/users/fabien/followers","following_url":"https://api.github.com/users/fabien/following{/other_user}","gists_url":"https://api.github.com/users/fabien/gists{/gist_id}","starred_url":"https://api.github.com/users/fabien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabien/subscriptions","organizations_url":"https://api.github.com/users/fabien/orgs","repos_url":"https://api.github.com/users/fabien/repos","events_url":"https://api.github.com/users/fabien/events{/privacy}","received_events_url":"https://api.github.com/users/fabien/received_events","type":"User","site_admin":false},"created_at":"2015-03-06T21:18:03Z","updated_at":"2015-03-06T21:18:03Z","body":"@raymondfeng \r\n\r\n1. as explained, in the case of `prototype.updateAttributes` its' called `currentInstance`; there will not be an `instance` - otherwise it would still not be clear that one should work with `ctx.data` then.\r\n\r\nSee: https://github.com/fabien/loopback-datasource-juggler/blob/feature/op-hooks/lib/dao.js#L1911\r\n\r\n2. no, there are no further changes - except for `instance` with `delete` hooks  - BC is completely preserved. "}}