执行(默认):SELECT id
,title
,slug
,content
,sorting
,createdAt
,updatedAt
FROM Pages
AS Page
WHERE Page
。id
='51';
执行(默认):UPDATE Pages
SET title
='gaffer',slug
='home',content
='Home testingaaaaaaaaaaaaaaaaaaaaaaaaaa',updatedAt
=' 2018-04-25 21:02:07'在哪里id
='家'
主要的问题是,当我收到我的编辑表格时,它给我ID中的ID因为我为它编写了代码,但是当我更新它给我的ID是我的SLUG这就是为什么我的数据库未更新任何帮助将不胜感激
/*
* GET Editing page
*/
router.get('/edit-page/:id', function (req, res) {
models.Page.findOne({
where: {
id:req.params.id
}
})
.then(function(page){
id=page.id,
title=page.title,
slug=page.slug,
content=page.content
})
.then(function(){
res.render('admin/edit_page');
})
.catch(function(err){
console.log(err);
})
});
/*
* POST Edit Page
*/
router.post('/edit-page/:id', function (req, res) {
req.checkBody('title', 'Title must have a value.').notEmpty();
req.checkBody('content', 'Content must have a value.').notEmpty();
var title = req.body.title;
var slug = req.body.slug.replace(/\s+/g, '-').toLowerCase();
// if (slug == " ")
// slug = title.replace(/\s+/g, '-').toLowerCase();
var content = req.body.content;
var id = req.body.id;
var condition={
where:
{id:req.params.id}
};
var values={
title:req.body.title,
slug:req.body.slug,
content:req.body.content
};
options={multi:true};
var errors = req.validationErrors();
if (errors) {
res.render('admin/edit_page', {
errors: errors,
title: title,
slug: slug,
content: content,
id:id
});
} else {
// models.Page.find({
// where: {
// id:req.params.id
// }
// })
// .then(function(page){
// if(Page){
models.Page.update(values,{...condition,...options}) //ES6 sprade operator
.then(function(page){
res.render('admin/pages');
})
.catch(function(err){
console.log(err);
})
}
});