四好公路
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.
 
 
 
 

28 lines
874 B

'use strict';
module.exports = function(Resource, resource, association) {
// access points
var subResourceName =
association.target.options.name.singular.toLowerCase();
var associatedResource = new Resource({
app: resource.app,
sequelize: resource.sequelize,
model: association.target,
endpoints: [resource.endpoints.singular + '/' + subResourceName],
actions: ['read']
});
// @todo: this could be improved...
associatedResource.associationOptions = resource.associationOptions;
associatedResource.controllers.read.includeAttributes = [ association.identifierField ];
associatedResource.read.send.before(function(req, res, context) {
if (this.resource.associationOptions.removeForeignKeys)
delete context.instance.dataValues[association.identifierField];
context.continue();
});
return associatedResource;
};