0

I'm using Sequelize with Node and I have an instance of a model called athlete. I'm trying to insert it into my database using the save() function but it is returning this:

TypeError: athlete.save is not a function

Here is my code snippet :

console.log("Athlete: " + athlete);
athlete.save().then(function() {
    console.log("Inserted Athlete");
    callback(null, athlete);
}).catch(function (err) {
    console.log("Inserted athlete with error: " + err);
    callback(err, null);
});

The log prints this:

Athlete: [object SequelizeModel]

athlete is created from a class method in a Sequelize model definition file.

2 Answers 2

1

Turns out SequelizeModel is not the correct type of object. It needs to be an object of type SequelizeInstance in order to be saved using the save() function.

Sign up to request clarification or add additional context in comments.

1 Comment

by using model.build({}) eg ` Athlete.build ( {name: 'Darren', age: 28} ) `
0

Try do build your instance before save:

    const athlete = Athlete.build(req.body,
        {
        fields: ['athlete']
        })
    .save()
    .then( // . //)
    .catch(err => {res.json(err)})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.