我的風帆多對多協會已經停止保存更改,也就是說,如果我取消選中我的複選框列表中的某個項目,或者選擇一個新項目,則不會保存更改(已填充到連接表)。風帆多對多協會無法保存
它曾經工作,雖然我不知道它被打破了多久。
頁面上的所有其他字段保存正確。
所以我知道它的大部分機制都是正確的,只是多對多的關聯,即更新連接表中的活動記錄列表。
任何提示,我可以在我的保存中做錯嗎?
我有以下型號:
/**
* User.js
*/
module.exports = {
attributes: {
projects: {
collection: 'project',
via: 'users'
},
}
/**
* Project.js
*/
module.exports = {
attributes: {
users: {
collection: 'user',
via: 'projects',
dominant: true
},
}
在我的形式,我返回一個複選框列表像這樣
{ projectname: 'AS Story Database',
userlist: [ '10', '3', '1' ], <-- this line is the many to many line from the check boxs
projecttype: 'Development',
companyid: '1',
startdate: 'Sat Jan 01 2011 00:00:00 GMT+1100 (AUS Eastern Daylight Time)',
enddate: '' }
}
我試圖填充結果集
Project.findOne({'id':id})
.populate('users') <--------- heres the populate I added but didnt seem to have effect
.exec(function(err,project){
這是我的帆控制器中的保存對話框
var a=req.param('project',null);
console.log(a); <-- note this is where the json above is output
project.projecttype= a.projecttype,
project.projectname= a.projectname,
project.companyid= a.companyid,
project.users= a.userlist, <-- this is the many to many association that used to work
project.startdate = a.startdate,
project.enddate = a.enddate
project.save(function(err,updated){ <-- here is the save function
if (err) {
req.session.flash = {'err':err};
sails.controllers.project.edit(req,res);
}else{
req.session.flash = {};
res.redirect('project/index');
}
});
您指定數組'project.users'變量,而不是使用['。新增()' ](http://sailsjs.com/documentation/reference/waterline-orm/populated-values/add)/ ['卸下襬臂()'](http://sailsjs.com/documentation/reference/waterline-orm/填充值/刪除)。它曾經以這種方式工作過嗎? – Sangharsh
是的! 根據文檔,這是它應該工作的方式。 雖然我得出結論,但我需要自己編寫一個深度更新機制。 –
您能否提供指向'project.users'可以直接分配給數組的文檔的鏈接? – Sangharsh