I try to use the "findOrCreate" function of SequelizeJS but it doesn't work.
The variable "created" is "undefined", so I don't know why because it's a variable used by SequelizeJS...
for( var i = 0; i < tags.length; i++ ){
global.db.Tag.findOrCreate({name: tags[i]}).success( function(tag, created){
if( created ){
global.db.PostTag.create({
PostId: id,
TagId: tag.id
});
}
});
}
Finder methods are the ones that generate SELECT queries. By default, the results of all finder methods are instances of the model class (as opposed to being just plain JavaScript objects). This means that after the database returns the results, Sequelize automatically wraps everything in proper instance objects.
Automatically creates tables in MySQL database if they don't exist by calling await sequelize.
Sequelize will assume your table has a id primary key property by default.
Sequelize set up Install Sequelize database driver for the database you would like to use by running one of the commands below. Install npm package Sequelize-CLI. Create a project folder. In your project folder path, run the command below to initialize Sequelize in the folder.
I had the same problem. Upgrading from 1.7.0-alpha2 to 2.0.0-alpha2 solved it. Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With