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
Post a Comment