sequelize.js - custom serialisation of sequelize toJSON -


currently sequelize serialize instance this

 id: 2,   title: 'bla bla',   url: 'https://mail.google.com/mail/u/0/#inbox/14c6002a21ae0679',   createdat: sat mar 28 2015 18:58:42 gmt+0800 (sgt),   updatedat: sat mar 28 2015 18:58:42 gmt+0800 (sgt),   userbookmarks:    { createdat: sat mar 28 2015 18:59:16 gmt+0800 (sgt),      updatedat: sat mar 28 2015 18:59:16 gmt+0800 (sgt),      userid: 1,      bookmarkid: 2 } } 

i want highlight way relationship serialized. bookmark model , want build or use lib generically modifies relationship form userbookmarks xxx user:[];

any ideas ?

you can provide custom tojson function:

var model = sequelize.define(name, attributes, {     instancemethods: {         tojson: function () {             var values = this.constructor.prototype.tojson.call(this);              // magic here          }     }  }); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -