sails.js - including toMany list of IDS in REST response from sailsjs -
i have sails model ("folders"):
module.exports = attributes: { name: type: 'string' parent: model: 'folder' folders: collection: 'folder' via: 'parent' when retrieve via rest api, want response looks like:
[ { name: 'foo', parent: 34, folders: [292, 358] } ] however, sails leaves out "folders" attribute.
what simplest way tomany included (this 1 example -- there more tomany's, otoh don't want them included -- should configurable per-relation)?
it seems "tomany" associations suppressed default "tojson" method sails provides.
to override, in object definition, inside of objects, override tojson:
_ = require 'lodash' attributes: { ... tojson: ()-> return _.extend {}, this use defaults provided "json.stringify", , "tomany" relationships sent lists of ids (if adapter has returned model).
Comments
Post a Comment