tgriesser/bookshelf — pull request #165 by johanneslumpe (2014-01-04 20:20:39+00:00)
Title: Adding support to setting virtuals

Sorry, a bit late, but I just added this in. Virtuals can now also have a setter function:

var User = Bookshelf.Model.extend({
tableName: 'users',
outputVirtuals: true,
virtuals: {
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
},
fullNameUpperCase: {
get: function() {
return this.get('firstName') + ' ' + this.get('lastName');
},

set: function(value) {
value = value.split(' ');
this.set('firstName', value[0].toUpperCase());
this.set('lastName', value[1].toUpperCase());
},
}
},
});