【发布时间】:2019-03-14 22:36:50
【问题描述】:
如何在 Adonis 中关联 oneToMany 关系中的值数组。
文档显示以下内容以关联单个值
const Profile = use('App/Models/Profile')
const User = use('App/Models/User')
const user = await User.find(1)
const profile = await Profile.find(1)
await profile.user().associate(user)
如果我的表单提交了一个包含多个用户 ID 的数组怎么办 我知道我可以使用 array.map 并循环遍历每一个,但这是一个异步命令,我的控制器会在 map 完成之前尝试响应客户端。
users.map(async (u)=>{
let user = await User.find(u)
await profile.user().associate(user)
})
return //I think this would return before the above map function completed.
【问题讨论】:
标签: javascript arrays adonis.js associate