{"action":"opened","issue":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/1508","repository_url":"https://api.github.com/repos/tgriesser/bookshelf","labels_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/1508/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/1508/comments","events_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/1508/events","html_url":"https://github.com/tgriesser/bookshelf/issues/1508","id":205040459,"number":1508,"title":"toJSON/serialize with plugins.virtuals breaks omitNew option","user":{"login":"jgr3go","id":3149277,"avatar_url":"https://avatars.githubusercontent.com/u/3149277?v=3","gravatar_id":"","url":"https://api.github.com/users/jgr3go","html_url":"https://github.com/jgr3go","followers_url":"https://api.github.com/users/jgr3go/followers","following_url":"https://api.github.com/users/jgr3go/following{/other_user}","gists_url":"https://api.github.com/users/jgr3go/gists{/gist_id}","starred_url":"https://api.github.com/users/jgr3go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgr3go/subscriptions","organizations_url":"https://api.github.com/users/jgr3go/orgs","repos_url":"https://api.github.com/users/jgr3go/repos","events_url":"https://api.github.com/users/jgr3go/events{/privacy}","received_events_url":"https://api.github.com/users/jgr3go/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-02-03T00:37:12Z","updated_at":"2017-02-03T00:37:12Z","closed_at":null,"body":"If you have virtuals defined on the model, even when using `omitNew`, the virtuals are returned.  \r\n\r\n```\r\nlet Person = bookshelf.Model.extend({\r\n  virtuals: {\r\n    fullName: function() {\r\n      return this.get('firstName') + ' ' + this.get('lastName');\r\n    }\r\n  }\r\n});\r\nlet p = new Person({firstName: 'Jon', lastName: 'Smith'});\r\np.toJSON({omitNew: true}); // { fullName: 'Jon Smith' }\r\n```\r\n\r\nThis becomes a problem when loading relations that could be null.  This virtual turns into `{ fullName: 'undefined undefined' }` for instance, when it should be returning `null`. \r\n"}}
{"actor":{"display_login":"jgr3go"}}