mysql - bookshelfJS: idAttribute to specify alternate id name -


i've added idattribute line code in hopes allow me specify alternate name id field:

bookshelf.apiuser = bookshelf.model.extend({     tablename: 'users',     idattribute: 'userid' }); 

but breaks node project. long id field named 'id', project works; how can name id field userid , have bookshelfjs know do?

the value of idattribute needs column in table. purpose of tell bookshelf column should use id field thing forge , relations. cannot change name of field specifying different name there. way know how change field name in model change actual column name

----- update ----

not cares, can work around issue using virtual , hidden plugins hide actual id attribute , provide virtual 1 different name.

first include plugins

var bookshelf = require('bookshelf'); bookshelf.plugin('virtuals'); bookshelf.plugin('visibility'); 

then define model id attribute hidden , virtual attribute get/set id attribute

bookshelf.apiuser = bookshelf.model.extend({     tablename: 'users',     hidden: ['id'],     virtuals: {         userid: {             get: function() {                 return this.get('id');             },             set: function(value) {                 return this.set('id', value);             }         }     } }); 

you still need id field named 'id' in database. or can rename primary key in database userid.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -