首先,似乎您正试图在一次调用中从不同的模型以及它们之间的关系创建记录。。。目前,App-Maker还不能消化这么复杂的一餐。您很可能需要将流程分为多个步骤:
-
创建(持久化)议程项目
-
创建AgendaDocs记录以及与AgendaItem的关系
类似流程在中实现
Travel Approval
模板应用程序,但它与您的不完全相同,因为它不会批量创建关联。
回到原来的问题。是的,有可能有多个
草稿
,但不使用创建数据源。您正在寻找
Manual Save Mode
. 在某处
完美的世界
您的代码与此类似:
// AgendaItems in Manual Save mode
var agendaDs = app.datasources.AgendaItems;
// this line will create item on client and automatically push it
// to ds.items and set ds.item to it.
agendaDs.createItem();
var agendaDraft = agendaDs.item;
// Field values can be populated from UI via bindings...
agendaDraft.Type = 'X';
agendaDraft.Description = 'Y';
// onDocumentSelect Drive Picker's event handler
var docsDs = agendaDs.relations.AgendaDocs;
result.docs.forEach(function(doc) {
// this line will create item on client and automatically push it
// to ds.items and set ds.item to it...however it will throw an exception
// with this message:
// Cannot save a foreign key association for the 'AgendaItem'
// relation because the target record has not been persisted
// to the server. To fix this, call saveChanges()
// on the data source for that record's model: AgendaItem
docsDs.createItem();
var docDraft = docsDs.item;
docDraft.DocTitle = doc.name;
docDraft.DocURL = doc.url;
docDraft.DriveID = doc.id;
});
// submit button click
agendaDraft.saveChanges();