ios - 在 Vapor 中寻找祖父母
问题描述
我目前正在将 Vapor 用于数据库并且遇到了我可以使用一些帮助的障碍。
我目前有一个Business
对象,它有[AccessPoint]
孩子。每一个AccessPoint
,本身就有数个[AccessPointContactMethod]
。
AnAccessPointContactMethod
可以AccessPoint
通过检查其accessPointID
在创建父子关系时由 Vapor 设置的属性来引用其父级。
事实上,我使用它来确保当AccessPointContactMethod
创建一个新的时,如果父级AccessPoint
已经有一个具有相同地址的子级,我们会中止发布请求:
return AccessPointContactMethod.query(on: req).group(.and) { and in
and.filter(\.contactMethodAddress == contactMethod.contactMethodAddress)
and.filter(\.accessPointID == contactMethod.accessPointID)
}.all()
.flatMap(to: AccessPointContactMethod.self) { methods in
if methods.isEmpty {
return contactMethod.save(on: req)
}
else {
let duplicateContactMethodStatus = HTTPResponseStatus.custom(code: 600, reasonPhrase: "Duplicate Contact Method")
throw Abort(duplicateContactMethodStatus)
}
}
所以这导致我遇到了我遇到的问题。目前,我只检查其中是否有重复的地址AccessPoint
,但我想做的是检查AccessPoint
属于一个的所有对象Business
,如果有任何AccessPoint
包含AccessPointContactMethod
相同地址的对象,那么我们中止请求.
因此,在我看来,我需要一种方法来获取Business
祖父母对象并遍历[AccessPoint]
子对象以查找任何重复项。
Vapor、响应式编程、数据库对我来说都是全新的,所以我确信我没有很好地描述这个问题,但如果有人能理解我想要做什么并且有任何想法,我会非常感激!
解决方案
推荐阅读
- c# - 无论日期如何,如何设置特定的时间范围(例如从 07:00 到 12:00)
- apache-kafka - 计算 Kafka 分区以实现特定的吞吐量
- python - 地理编码超时。错误是由数据框表引起的吗?
- php - PHP - 将未定义的变量与空变量区分开来
- c++ - Google Jam 2018 参议院疏散
- python - 如何将包含文件名和信息的文件分别拆分为多个文件?
- r - R:如何读取一列,查找一个值并根据此搜索计算另一列中的某些内容?
- unix - Lunix 服务器通过 Curl 返回旧的 SSL 证书
- r - 如何在r中获得具有条件的唯一行?
- c - 在这种情况下,strcmp 如何在 C 中工作?我有一个要循环的数组和一个需要与数组中的每个元素进行比较的字符