如何填充多对多关系
How to populate many to many relationship
我有两个模型之间的多对多关系。但是我不知道如何创建一个表单或 table 来将记录添加到多对多关系中。我正在使用 Google Drive Tables。
我试图查看关系是否设置正确,我导出数据并手动填充为多对多关系创建的 sheet 中的键。我检查了使用下拉列表来过滤数据并且效果很好。
这可能是最基本的,但我就是不知道如何去做。请帮忙。
毛里西奥
在 object/api 级别上具有多对多关系,App Maker 会提供一组相关记录。假设我们有 'Questions' 和 'Tags' 具有多对多关系的模型。我们可以从关系的任何一端创建关联:
// create association from question side
question.Tags.push(tag);
// create association from tag side
tag.Questions.push(question);
Multiselect Widget 将完成这项工作。假设我们需要为问题添加一些标签,我们需要将多选绑定到我们数据库中的所有标签,然后绑定看起来类似于此
// binding for Multiselect's names (.. - two dots mean projection)
@datasources.Tags.items..Name
// binding for Multiselect's options
@datasources.Tags.items
// binding for Multiselect's values
// assuming that parent widget is bound to datasource with question
// and `@datasource.item` is question
@datasource.item.Tags
with Suggest Box and Dropdown 小部件绑定将类似于多选绑定,但您需要编写一些脚本:
// onValueEdit event handler
// assuming that parent widget is bound to datasource with question
widget.datasource.item.Tags.push(newValue);
我有两个模型之间的多对多关系。但是我不知道如何创建一个表单或 table 来将记录添加到多对多关系中。我正在使用 Google Drive Tables。
我试图查看关系是否设置正确,我导出数据并手动填充为多对多关系创建的 sheet 中的键。我检查了使用下拉列表来过滤数据并且效果很好。
这可能是最基本的,但我就是不知道如何去做。请帮忙。
毛里西奥
在 object/api 级别上具有多对多关系,App Maker 会提供一组相关记录。假设我们有 'Questions' 和 'Tags' 具有多对多关系的模型。我们可以从关系的任何一端创建关联:
// create association from question side
question.Tags.push(tag);
// create association from tag side
tag.Questions.push(question);
Multiselect Widget 将完成这项工作。假设我们需要为问题添加一些标签,我们需要将多选绑定到我们数据库中的所有标签,然后绑定看起来类似于此
// binding for Multiselect's names (.. - two dots mean projection)
@datasources.Tags.items..Name
// binding for Multiselect's options
@datasources.Tags.items
// binding for Multiselect's values
// assuming that parent widget is bound to datasource with question
// and `@datasource.item` is question
@datasource.item.Tags
with Suggest Box and Dropdown 小部件绑定将类似于多选绑定,但您需要编写一些脚本:
// onValueEdit event handler
// assuming that parent widget is bound to datasource with question
widget.datasource.item.Tags.push(newValue);