I have a Bookshelf.js model. I want to be able to set and get attributes for this model that are not constant in the database.
For example, let's say I have a model that looks like this:
var Domain = bookshelf.Model.extend({ tableName: 'domains', initialize: function() { this.on('creating', this.setDomainName); }, setDomainName: function() { this.set('name', getDomainFromUrl(this.url)); } });
With a diagram that looks like this:
knex.schema.createTable('domains', function (table) { table.increments().index(); table.text('name').index(); table.timestamps(); });
I want to save the url attribute and then parse the URL in the domain before saving it.
When I try something like this:
new Domain({url: 'http://someurl.com/foo/bar'}).save()
I get an error message:
"column \"url\" of relation \"domains\" does not exist"
I looked and looked. I cannot find a way to add mutable attributes to the bookshelf.js model. I also could not find anything about adding custom getter and setter methods to the bookshelf.js model.
Any help or understanding appreciated!
source share