4

following the documentation I realize there's an option to allow bulk creation, but I don't understand where and how to set the option, here the code:

// Initializes the `test` service on path `/test`
const createService = require('feathers-sequelize');
const createModel = require('../../models/test.model');
const hooks = require('./test.hooks');

module.exports = function (app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');


//Where to put the multi option???
  const options = {
    Model,
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/test', createService(options));

  // Get our initialized service so that we can register hooks
  const service = app.service('test');

  service.hooks(hooks);
};

Thank you in advance.

Arc009
  • 43
  • 4

1 Answers1

4

The option is added to the options object:

// Initializes the `test` service on path `/test`
const createService = require('feathers-sequelize');
const createModel = require('../../models/test.model');
const hooks = require('./test.hooks');

module.exports = function (app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');


//Where to put the multi option???
  const options = {
    Model,
    paginate,
    multi: [ 'create' ] // list of method names
    // or for everything
    // multi: true 
  };

  // Initialize our service with any options it requires
  app.use('/test', createService(options));

  // Get our initialized service so that we can register hooks
  const service = app.service('test');

  service.hooks(hooks);
};
Daff
  • 43,734
  • 9
  • 106
  • 120
  • Thank you so much, I solved it yesterday, but now I have another issue with not at all clues. After a successfully multi-create i have back the response but with all id(s) set to Null. [ { "id": null, "text": "entity1", "createdAt": "2019-03-20T14:11:03.448Z", "updatedAt": "2019-03-20T14:11:03.448Z" }, { "id": null, "text": "entity2", "createdAt": "2019-03-20T14:11:03.448Z", "updatedAt": "2019-03-20T14:11:03.448Z" } ] Any idea? – Arc009 Mar 20 '19 at 14:11
  • how to implement multi patch and remove, without using multi: ['patch', 'remove'] in service? – ramboeistblast Nov 17 '20 at 10:20