I get an issue using SequelizeJS and NodeJS.
My error message when I execute the npm bin/www
command :
EventEmitter#success|ok is deprecated, please use promise-style instead.
Executing (default): CREATE TABLE IF NOT EXISTS `ArticleCategories` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `ArticleCategories`
I don't understand why the CREATE TABLE
is executed because my table is already on place...
My model :
module.exports = function (db, Types) {
var ArticleCategory = db.define('ArticleCategory', {
name: {
type: Types.STRING
},
}, {
classMethods:{
associate: function (models) {
ArticleCategory.hasMany(models.Article);
}
}
});
return ArticleCategory;
};
And the dao, of the current model :
var dbContext = require('./../../db/DbContext');
var _ = require('lodash');
var ArticleCategoryDao = function () {
this.context = dbContext.entities;
};
_.extend(ArticleCategoryDao.prototype, {
getAll: function (callback) {
return this.context.ArticleCategory.findAll({include: [{ model: this.context.Article}]});
},
get: function (id, callback) {
return this.context.ArticleCategory.find(id);
},
save: function(properties, callback){
this.context.ArticleCategory.create(properties)
.success(function (category) {
callback(null, category);
})
.error(function (error) {
callback(error, null);
});
},
update: function (properties, callback) {
this.get(properties.id).success(function (category) {
if(category){
category.updateAttributes(properties).success(function (category) {
callback(null, category);
}).error(function (error) {
callback(error, category);
});
}else{
callback('Aucune catégorie avec l\'id :' + properties.id, null);
}
});
},
delete: function (id, callback) {
this.context.ArticleCategory.find(id).success(function (category) {
if(category){
category.destroy().success(callback);
}
else{
callback('Aucune catégorie avec l\'id :' + id);
}
})
.error(callback);
}
});
module.exports = ArticleCategoryDao;