如何建立多对多关系 [英] How to populate many to many relationship

查看:75
本文介绍了如何建立多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个模型之间有一个多对多关系.但是我无法弄清楚如何创建一个表单或表格来将记录添加到多对多关系中.我正在使用Google云端硬盘表.

I have a MANY-to-MANY relation between two models. But I cannot figure out how to create a form or table to add records to a many to many relation. I am using Google Drive Tables.

我试图查看该关系是否设置正确,我导出了数据并手动在为多对多关系创建的工作表中填充了键.我检查了使用下拉列表过滤数据,它很好用.

I tried to see if the relation is well set, I exported the data and manually populated the keys in the sheet created for the many to many relation. I checked using dropdowns to filter data and it works well.

这可能是基本的,但我只是不知道如何去做.请帮忙.

This is probably basic but I just can't find out how to do it. Please help.

毛里西奥

推荐答案

在对象/api级别具有多对多关系,App Maker会提供一系列相关记录.假设我们有具有多对多关系的问题"和标签"模型.我们可以从关系的任何一端创建关联:

With many-to-many relation on the object/api level App Maker gives an array of related records. Let's say we have 'Questions' and 'Tags' models with many-to-many relation. We can create association from any end of the relation:

// create association from question side
question.Tags.push(tag);

// create association from tag side
tag.Questions.push(question);

Multiselect窗口小部件即可完成此工作.假设我们需要为问题添加一些标签,并且需要将multiselect绑定到数据库中所有的标签,然后绑定看起来与此类似

Multiselect Widget will do this work for. Let's say we need to add some tags for a questions and we need to bind multiselect to all tags we have in our DB then binding will look similar to this

// 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 widgets binding will be similar to multiselect's one but you'll need to do some scripting:

// onValueEdit event handler
// assuming that parent widget is bound to datasource with question
widget.datasource.item.Tags.push(newValue);

这篇关于如何建立多对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆