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
});
}
});
}
I had the same problem. Upgrading from 1.7.0-alpha2 to 2.0.0-alpha2 solved it. Cheers
global.db.Tag.findOrCreate({
where:{
name: tags[i]
},
defaults: {
//properties you want on create
}
}).then( function(tag){
var created = tag[1];
tag = tag[0]; //new or found
if( created ){
}
}).fail(function(err) {
});