Comments (7)
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.
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.
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.
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.
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.
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.
realised readme was kinda misleading too, updated
from sequelize-fixtures.
Related Issues (20)
- Grunt: add support for async loading of models + use grunt built-in logging
- Unhandled rejection TypeError: Cannot set property '%' of undefined
- Add support for generating fixtures HOT 1
- Distinguish between stdout and stderr when logging
- Add test coverage for grunt task
- TypeError: Cannot read property 'warn' of undefined HOT 5
- Question: Mapping JSON to Model Entity?
- TypeError: Cannot read property 'id' of null HOT 2
- Dialect needs to be explicitly supplied as of v4.0.0'
- Missing release notes for 1.2 HOT 4
- CI build status not appearing in Pull Request review on github HOT 4
- The link to official example of how to load models is not working HOT 1
- Ability to load multiple items in an array HOT 1
- When to use transformFixtureDataFn vs modifyFixtureDataFn HOT 1
- Proposed fix: Fix `through` associations on join tables HOT 7
- Duplicate records being inserted HOT 1
- Add flag to suppress usage of use of property setter methods in case they use instance methods [feedback wanted] HOT 1
- sequelize deprecated Model.find has been deprecated, please use Model.findOne instead at HOT 6
- Fail yarn audit HOT 1
- NEW MAINTAINER WANTED HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sequelize-fixtures.