I have following models in SequelizeJS. It produces
Language.hasMany(models.Shop, {
as: "languages",
foreignKey: "language_id",
through: 'shop_has_languages'
});
Shop.hasMany(models.Language, {
as: "languages",
foreignKey: "shop_id",
through: 'shop_has_languages'
});
When I want to save a language data, there is no problem:
INSERT INTO `languages` (`id`,`code`,`name`,`flag`) VALUES (DEFAULT,'en','English','gb');
But when I want to UPDATE this data, it produces:
SELECT * FROM `languages` WHERE `shops`.`id`='1' LIMIT 1;
NodeJS code that generate this is:
exports.language = function(req, res, next, id) {
console.log('id => ' + id);
db.Language.find({ where: {id: id}}).success(function(language){
if(!language) {
return next(new Error('Failed to load language ' + id));
} else {
req.language = language;
return next();
}
}).error(function(err){
return next(err);
});
};
And I am getting error beacuse "WHERE shops
.id
='1' LIMIT 1;"
Where am I wrong? Is there a bug in SequelizeJS?