Giter Club home page Giter Club logo

Comments (7)

domasx2 avatar domasx2 commented on July 25, 2024

hi,

In data a model is referenced as LinkedServices, but its actually named LinkedService

Could provide a better error message for these cases, will update

from sequelize-fixtures.

lawli3t avatar lawli3t commented on July 25, 2024

The same error still persists when I change the line to:
LinkedServices: require("./app/models/linkedServices"),

I managed to make the exact same JSON work though by making it a module and exporting/importing it.

from sequelize-fixtures.

lstanard avatar lstanard commented on July 25, 2024

Hey @lawli3t, I'm currently having this same issue. Can you provide more insight into how you got this working? I have my test data setup with module.exports, but how did you import it? Thanks!

from sequelize-fixtures.

lawli3t avatar lawli3t commented on July 25, 2024

here is my snippet on importing it:

const models = require("./app/models");
const fixtures = require("./app/tests/data/sampledata")

var sequelize_fixtures = require("sequelize-fixtures"),
    modelDict = {
        User: require("./app/models/user"),
        // and so on .....
    };

models.sequelize.sync( {force:true} ).then(() => {
    sequelize_fixtures.loadFixtures(fixtures, models).then(function(){
        console.dir("Data created succesfully");
    });
});

from sequelize-fixtures.

sublet avatar sublet commented on July 25, 2024

I'm having the same issue. I even dumbed it down to just use a fixture that is a variable and I am still getting the Unhandled rejection TypeError: Cannot convert undefined or null to object error.

Any help would be greatly appreciated.

module.exports = function (sequelize, DataTypes) {
    return sequelize.define("foo", {
        propA: {type: DataTypes.STRING},
        propB: {type: DataTypes.INTEGER},
        status: {type: DataTypes.BOOLEAN}
    });
};
'use strict';

var sequelize_fixtures = require('sequelize-fixtures'),
    models = {
      Foo: require("../src/models/foo")
    };

var fixtures = [
  {
    model: 'Foo',
    data: {
      propA: 'bar',
      propB: 1
    }
  },
  {
    model: 'Foo',
    data: {
      propA: 'baz',
      propB: 3
    }
  }
];

sequelize_fixtures.loadFixtures(fixtures, models).then(function(){
  console.log('Complete!');
});

from sequelize-fixtures.

domasx2 avatar domasx2 commented on July 25, 2024

It finally dawned on me :)

You're passing a model factory function rather than a model.

module.exports = function (sequelize, DataTypes) { //this is a factory function, not a model
    return sequelize.define("foo", { //this produces the actual model
        propA: {type: DataTypes.STRING},
        propB: {type: DataTypes.INTEGER},
        status: {type: DataTypes.BOOLEAN}
    });
};

Instead you should import models/foo using sequelize.import(). See official example: https://github.com/sequelize/express-example/blob/master/models/index.js#L17

And your sequelize_fixtures call should look like this:

const models = require('../src/models');
sequelize_fixtures.loadFixtures(fixtures, models).then(function(){
  console.log('Complete!');
});

I released a tiny update with dac38bf that will detect this error and provide a helpful message.

I'm now thinking that sequelize-fixtures shoud ask for an instance of sequelize instead of a models map, to prevent this kind of confusion...

from sequelize-fixtures.

domasx2 avatar domasx2 commented on July 25, 2024

realised readme was kinda misleading too, updated

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.