{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/736","labels_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/736/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/736/comments","events_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/736/events","html_url":"https://github.com/tgriesser/bookshelf/pull/736","id":75236795,"number":736,"title":"Run modelMethods on toJSON output not attributes","user":{"login":"tbranyen","id":181635,"avatar_url":"https://avatars.githubusercontent.com/u/181635?v=3","gravatar_id":"","url":"https://api.github.com/users/tbranyen","html_url":"https://github.com/tbranyen","followers_url":"https://api.github.com/users/tbranyen/followers","following_url":"https://api.github.com/users/tbranyen/following{/other_user}","gists_url":"https://api.github.com/users/tbranyen/gists{/gist_id}","starred_url":"https://api.github.com/users/tbranyen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbranyen/subscriptions","organizations_url":"https://api.github.com/users/tbranyen/orgs","repos_url":"https://api.github.com/users/tbranyen/repos","events_url":"https://api.github.com/users/tbranyen/events{/privacy}","received_events_url":"https://api.github.com/users/tbranyen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tgriesser/bookshelf/labels/discussion","name":"discussion","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-05-11T14:15:01Z","updated_at":"2015-06-16T12:32:39Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/tgriesser/bookshelf/pulls/736","html_url":"https://github.com/tgriesser/bookshelf/pull/736","diff_url":"https://github.com/tgriesser/bookshelf/pull/736.diff","patch_url":"https://github.com/tgriesser/bookshelf/pull/736.patch"},"body":"The best way I've found to remove a password from a user object is via\r\nthe `omit` method.  This matches up with the documentation that shows\r\nthe following example:\r\n\r\n``` javascript\r\nCustomer.login(email, password).then(function(customer) {\r\n  res.json(customer.omit('password'));\r\n})\r\n```\r\n\r\nThis works great until you use `withRelated` to fetch a user profile,\r\nfor instance.  `omit` will run on the `attributes` not the merged\r\noutput, so using the above example would strip out the fetched\r\nadditionals.\r\n\r\nThis PR is my naive solution at fixing the problem.  I updated the base\r\nmodel to use `toJSON` as well as the virtuals plugin.\r\n\r\nLet me know if anything else needs documenting or if is avoidable\r\nintentional behavior."},"comment":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/comments/112408681","html_url":"https://github.com/tgriesser/bookshelf/pull/736#issuecomment-112408681","issue_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/736","id":112408681,"user":{"login":"rhys-vdw","id":822105,"avatar_url":"https://avatars.githubusercontent.com/u/822105?v=3","gravatar_id":"","url":"https://api.github.com/users/rhys-vdw","html_url":"https://github.com/rhys-vdw","followers_url":"https://api.github.com/users/rhys-vdw/followers","following_url":"https://api.github.com/users/rhys-vdw/following{/other_user}","gists_url":"https://api.github.com/users/rhys-vdw/gists{/gist_id}","starred_url":"https://api.github.com/users/rhys-vdw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhys-vdw/subscriptions","organizations_url":"https://api.github.com/users/rhys-vdw/orgs","repos_url":"https://api.github.com/users/rhys-vdw/repos","events_url":"https://api.github.com/users/rhys-vdw/events{/privacy}","received_events_url":"https://api.github.com/users/rhys-vdw/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T12:32:39Z","updated_at":"2015-06-16T12:32:39Z","body":"> A safer approach would be to create a special case for the omit() method and use .toJSON() only in that case. What do you guys think?\r\n\r\nWell, this particular use case of `_.omit` is already handled by the visibility plugin. Consistency is very important, so I would be hesitant to make a special case here.\r\n\r\n> I can't think of any case where invert would be useful :\\ Why was it included in the first place?\r\n\r\n`invert` and friends were taken from [Backbone](http://backbonejs.org/#Model-Underscore-Methods). I've personally never used any of them. I actually can't think of any good use cases for Bookshelf, at least none none so frequent to justify them being in the API. I'd be interested to hear of some other uses.\r\n\r\nTo be honest I think these functions could provide unexpected behaviour either way, which is not a good sign. Maybe they should just be canned altogether in the name of simplicity? Or stripped from core and moved to a plugin? I think the latter might be the safest, as it provides support for those who depend on them. It could even have a config setting to change whether it's deep or shallow.\r\n\r\nSorry @tbranyen, I'm sure this isn't the response you were hoping for. It's still open for discussion though."}}