我有一个亲子关系,孩子们需要包装成数组怎么办?
event.testPrices = release.testPrices
final class Event: Content {
var id: String
var inProgress: Bool?
var name: String
var purpose: String?
var testPrices: [TestPrice]
init(id: String, name: String) {
self.id = id
self.name = name
}
}
extension Release {
var testPrices: Children<Release, TestPrice> {
return children(\.releaseId)
}
}
分配给错误:
不能将类型为'Children'的值分配为类型为[[TestPrice]'
答案 0 :(得分:1)
您可以使用查询形成Future
数组,然后map
数组。假设您在某个控制器/路由中,其中event
包含适当的Event
,而release
包含适当的Release
,请尝试以下操作:
{
release, event in
_ = release.testPrices.query(on:request).all().map { testP in
// testP is now [TestPrice]
event.testPrices = testP
}
}