简体   繁体   中英

Using epilogue, is it possible to get back a resource without associations?

I have

epilogue.resource({
  model: db.Question,
  endpoints: ['/api/questions', '/api/questions/:id'],
  associations: true
});

So when I hit /api/questions , I get back all the associations with the resources. Is there something I can pass to not get the associations in certain cases? Or should I create a new endpoint:

epilogue.resource({
  model: db.Question,
  endpoints: ['/api/questions2', '/api/questions2/:id']
});

One way of doing is by using milestones you can define milestone for list and read behaviour in certain case, you have access to req object so you can do changes accordingly

https://github.com/dchester/epilogue#customize-behavior

Here is an example of list call modification

// my-middleware.js
module.exports = {
  list: {
    write: {
      before: function(req, res, context) {
        // modify data before writing list data
        return context.continue;
      },
      action: function(req, res, context) {
        // change behavior of actually writing the data
        return context.continue;
      },
      after: function(req, res, context) {
        // set some sort of flag after writing list data
        return context.continue;
      }
    }
  }
};

// my-app.js
var epilogue = require('epilogue'),
    restMiddleware = require('my-middleware');

epilogue.initialize({
    app: app,
    sequelize: sequelize
});

var userResource = epilogue.resource({
    model: User,
    endpoints: ['/users', '/users/:id']
});

userResource.use(restMiddleware);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM