Giter Club home page Giter Club logo

Comments (7)

balexandre avatar balexandre commented on August 29, 2024

Did you try the wildcard? (that's what I use and it's been working fine for a long time... I never had the need to specify only some files)

sequelize_fixtures.loadFile('fixtures/*.json', models).then(() => {
 // ...
});

this is my initialization/index.js

const chalk = require('chalk');
const fixtures = require('sequelize-fixtures');

const models = require('./../server/models');
const logger = require('./../server/utilities/logger');

// from file
module.exports = (callback) => {
  fixtures
    .loadFile('./initialization/fixtures/*.json', models)
    .then(() => {
      logger.log(chalk.green('Test data added to database'));
      callback();
    });
};

from sequelize-fixtures.

Sorgrum avatar Sorgrum commented on August 29, 2024

The wildcard does work, but the order the fixtures load in matters. Using the wildcard seems to use alphabetical order.

So while the wildcard does work, it doesn't work for my case.
I ended up having multiple calls like this:

await sequelize_fixtures.loadFile("fixtures/user.json", models);
await sequelize_fixtures.loadFile("fixtures/authentication.json", models);

from sequelize-fixtures.

balexandre avatar balexandre commented on August 29, 2024

@Sorgrum

So while the wildcard does work, it doesn't work for my case.

to solve that problem, I use

001.user.json
002.authentication.json

as file names, and I know they will always follow the order I set up to be.

you can even name as

001.user.json
005.authentication.json
010.somethingelse.json

so in the future, you can have a file in between ...

from sequelize-fixtures.

Sorgrum avatar Sorgrum commented on August 29, 2024

Sure, I personally don't think that's a very elegant way of solving the problem, but regardless the usage docs say this should work:

    //array of files
    sequelize_fixtures.loadFiles(['fixtures/users.json', 'fixtures/data*.json'], models).then(function(){
        doStuffAfterLoad();
    });

and it hadn't been working for me.

from sequelize-fixtures.

balexandre avatar balexandre commented on August 29, 2024

@Sorgrum I do prefer the file editing than edit all the time the function...

:)

from sequelize-fixtures.

Sorgrum avatar Sorgrum commented on August 29, 2024

Sure, so maybe we should just update the docs to reflect that passing in an array of files isn't a valid way to load fixtures?

from sequelize-fixtures.

matmar10 avatar matmar10 commented on August 29, 2024

@Sorgrum can you raise a PR with a change to the README.md you feel is appropriate? Thanks!

from sequelize-fixtures.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.