Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toJSON/serialize with plugins.virtuals breaks omitNew option #1508

Closed
jgr3go opened this issue Feb 3, 2017 · 1 comment
Closed

toJSON/serialize with plugins.virtuals breaks omitNew option #1508

jgr3go opened this issue Feb 3, 2017 · 1 comment

Comments

@jgr3go
Copy link
Contributor

jgr3go commented Feb 3, 2017

If you have virtuals defined on the model, even when using omitNew, the virtuals are returned.

let Person = bookshelf.Model.extend({
  virtuals: {
    fullName: function() {
      return this.get('firstName') + ' ' + this.get('lastName');
    }
  }
});
let p = new Person({firstName: 'Jon', lastName: 'Smith'});
p.toJSON({omitNew: true}); // { fullName: 'Jon Smith' }

This 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.

jgr3go added a commit to jgr3go/bookshelf that referenced this issue Feb 3, 2017
Playrom added a commit that referenced this issue Jun 29, 2017
#1508 - Fixing virtuals when `omitNew=true`;
@Playrom
Copy link
Contributor

Playrom commented Jun 29, 2017

Fix Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants