mardi 4 août 2015

Sailsjs Barrels fixtures required associations

I'm building Sails.js application and refactoring my tests to use Barrels fixtures. One of my model has required association. I read the instructions in Barrels repo about required associations. Below is my code which I use to load the fixtures. I keep getting an error about not passing Project to Activity (Activity model has a required association to 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 switch automatic association off in second populate and it looks like that Activities are created but their project field will get plain number defined in fixtures. I don't really trust it being correct always even though I use sails-disk for testing db.

So what is the problem here? Below is same code as one above but with callbacks wrapped into promise and auto-association switched off:

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);
        });

    });

Aucun commentaire:

Enregistrer un commentaire