四好公路
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
1.1 KiB

'use strict';
module.exports = function(Resource, resource, association) {
// access points
var subResourceName =
association.target.options.name.plural.toLowerCase();
var associatedResource = new Resource({
app: resource.app,
sequelize: resource.sequelize,
model: association.target,
endpoints: [
resource.endpoints.plural + '/:' + association.identifierField + '/' + subResourceName,
resource.endpoints.plural + '/:' + association.identifierField + '/' + subResourceName + '/:' + association.target.primaryKeyField
],
actions: ['read', 'list']
});
// @todo: this could be improved
associatedResource.associationOptions = resource.associationOptions;
associatedResource.controllers.read.includeAttributes = [ association.identifierField ];
associatedResource.controllers.list.includeAttributes = [ association.identifierField ];
associatedResource.list.fetch.before(function(req, res, context) {
// Filter
context.criteria = context.criteria || {};
context.criteria[association.identifierField] = req.params[association.identifierField];
context.continue();
});
return associatedResource;
};