Sailsjs barrel accessories need associations

I am creating a Sails.js application and refactoring my tests to use Barrels fixtures. One of my models requires association. I have read the instructions in the Barrels repo about mandatory associations. Below is my code that I am using to load the fixtures. I keep getting the error about not passing Project to Activity (the Activity model needs an association with Project).

var barrels = Promise.promisifyAll(new Barrels(process.cwd() + '/test/fixtures'));

return barrels.populateAsync(['project', 'integrations', 'user']).then(function() {
  return barrels.populateAsync(['activity']);
}).catch(function(err) {
  console.log(err);
});

      

I tried to turn off the auto association on the second fill and it looks like activities are being created, but their project field will get an equal number defined in fixtures. I really don't believe this is always correct, although I am using sails-disk for db testing.

So what's the problem? Below is code similar to the one above, but with callbacks disabled and automatic association disabled:

return new Promise(function (resolve) {
  var barrels = new Barrels(process.cwd() + '/test/fixtures');

  barrels.populate(['project', 'integrations', 'user'], function(err) {
    barrels.populate(['activity'], function(err) {
      resolve();
    }, false);
  });
});

      

+3


source to share





All Articles