You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to load a fixture into a sequelize object. It's very simple, a User model with a bunch of very basic string attributes. I'm not doing any associations or anything wacky there, simply trying to load one user at this point.
When I go to load this fixture I'm getting a "cannot read "firstname" of Undefined" error. This is being thrown on Line 75 of loader.js which is this:
var assoc = Model.associations[key], val = data[key];
Tracing this through the debugger I can see why the error is happening which is that the Model at this point is just a function definition and is not a real "User" object, thus there's no associations and the key (firstname in this case) can't be found.
I can see that the model definition has been loaded as the function definition is correct.
I am probably missing something but I'd have thought that Model would have had to be instantiated in order to create a new object of that class before you can start manipulating the associations and then later the attributes and building it.
Nowhere in the code for loader.js can I see this happening so I'm trying to work out where this happens?
Any help would be appreciated as I'm trying to get one basic example working before then generating a decent sized fixture to load in.
The text was updated successfully, but these errors were encountered:
Got to the bottom of this so here's the notes for someone who comes along behind.
If you have a broken up set of models (not all defined in the one file) then you'll more than likely be using a models/index.js file to define all the sequelize stuff as well as the relationships between them. This code will also have a loader for all your models so your application can use them.
Instead of defining the models to use the way it says to do it in the readme get your returned models from the index.js file
var models = require('./models');
And then pass that as the models definition to the fixture loader. This will have all of your models defined the way the fixture loader is assuming it will come with actual objects as the models.
I had a similar issue recently that I spent way too much time on. This is due to the way babel exports work. In short, I had to revert to module.exports as opposed to export default for my fixtures.
I'm trying to load a fixture into a sequelize object. It's very simple, a User model with a bunch of very basic string attributes. I'm not doing any associations or anything wacky there, simply trying to load one user at this point.
So my fixture looks like:
When I go to load this fixture I'm getting a "cannot read "firstname" of Undefined" error. This is being thrown on Line 75 of loader.js which is this:
Tracing this through the debugger I can see why the error is happening which is that the Model at this point is just a function definition and is not a real "User" object, thus there's no associations and the key (firstname in this case) can't be found.
I can see that the model definition has been loaded as the function definition is correct.
I am probably missing something but I'd have thought that Model would have had to be instantiated in order to create a new object of that class before you can start manipulating the associations and then later the attributes and building it.
Nowhere in the code for loader.js can I see this happening so I'm trying to work out where this happens?
Any help would be appreciated as I'm trying to get one basic example working before then generating a decent sized fixture to load in.
The text was updated successfully, but these errors were encountered: