2017-04-13 84 views
0

我只是想通过sailsjs在我的数据库创建一个新的输入,但没有错误,没有主菜出来。帆创建问题

这里是我的模型

module.exports = { 

    attributes: { 

    id: { type: 'integer'}, 
    entreprise_id: { type: 'integer'}, 
    employees_id: { type: 'string'}, 
    name : { type: 'string'}, 
    description_short: { type: 'string'}, 
    description_long: { type: 'string'}, 
    price: { type: 'string'}, 
    duration: { type: 'string'}, 
    at_home: {type: 'integer'}, 
    break_time: {type: 'integer'}, 
    many_customer: {type: 'integer'}, 
    last_minute_max: {type: 'integer'}, 
    precision_label: {type: 'string'}, 
    createdAt : { type: 'date' }, 
    updatedAt : { type: 'date' } 

    } 

} 

和脚本来创建主菜

Service.create({ 

    entreprise_id: entrepriseId, 
    employees_id:infos['employees_id'], 
    name :infos['name'], 
    description_short:infos['description_short'], 
    description_long:infos['description_long'], 
    price:infos['price'], 
    duration:infos['duration'], 
    at_home:infos['at_home'], 
    break_time:infos['break_time'], 
    many_customer:infos['many_customer'], 
    last_minute_max:infos['last_minute_max'], 
    precision_label:infos['precision_label'] 

}).exec(function(err, newService){ 

    if(err){ com.push({error:err})} 
    else{ 
    com.push(newService) 
    } 

}); 

我已经验证了信息数组中的所有信息都是空或包含的值,但没有的错误。 这个问题的关键在于我在我的阵列中没有错误,并且没有新的服务作为墙。

+0

1.什么是你的模型文件的名字吗?你如何运行脚本? 3. com数组初始化和检查在哪里? 4.你尝试把日志? – Sangharsh

+0

1. Service.js; 2.我在控制台sailsjs上用grunt运行脚本; 3.数组com在脚本的顶部初始化,我将它用作日志 – Nastyo

回答

0

我最后通过在回调函数中加入“if(err){return res.serverError(err);}”来得到错误。

我不得不防,其中在所需数量的空值等

for(n in infos){ 

    if(n=='entreprise_id'){ infos[n] = entrepriseId; } 
    if(n=="price"||n=="duration"||n=="at_home"||n=="break_time"||n=="many_customer"||n=="last_minute_max"){ 
    if(!infos[n]){ 
     infos[n]=0; 
    } 
    } 

} 

Service.create({ 
    entreprise_id: infos['entreprise_id'], 
    employees_id:infos['employees_id'], 
    name :infos['name'], 
    description_short:infos['description_short'], 
    description_long:infos['description_long'], 
    price:infos['price'], 
    duration:infos['duration'], 
    at_home:infos['at_home'], 
    break_time:infos['break_time'], 
    many_customer:parseInt(infos['many_customer']), 
    last_minute_max:parseInt(infos['last_minute_max']), 
    precision_label:infos['precision_label']   
}).exec(function(err, newService){ 

    if(err){ return res.serverError(err); } 
    com.push({news:newService}) 

});