大家好,
寻找对CoreData包装器框架的支持,名为Graph from CosmicMind (https://github.com/CosmicMind/Graph)。
不幸的是,除了绝对基础之外,文档很少(尽管似乎有很多非常强大的概念引入了b.t.w.)。
我想知道是否有人能--请--帮助我如何在1:N关系中选择/过滤实体。
考虑到以下结构..。
import Graph
let graph = Graph()
graph.clear()
let sectionA = Entity(type: "Section")
sectionA["id"] = 12
sectionA["name"] = "SectionA"
let sectionB = Entity(type: "Section")
sectionB["id"] = 2
sectionB["name"] = "SectionB"
let unitA = Entity(type: "Unit")
unitA["id"] = 122
unitA["name"] = "UnitA"
unitA["isExpensive"] = false
unitA.is(relationship: "UnitOfSection").of(sectionA)
let unitB = Entity(type: "Unit")
unitB["id"] = 19
unitB["name"] = "UnitB"
unitB["isExpensive"] = false
unitB.is(relationship: "UnitOfSection").of(sectionB)
let unitC = Entity(type: "Unit")
unitC["id"] = 7
unitC["name"] = "UnitC"
unitC["isExpensive"] = true
unitC.is(relationship: "UnitOfSection").of(sectionA)
let unitD = Entity(type: "Unit")
unitD["name"] = "UnitD"
unitD["isExpensive"] = true
unitD["id"] = 4
unitD.is(relationship: "UnitOfSection").of(sectionA)
graph.sync()
let unitsSearch = Search<Entity>(graph: graph).for(types: "Unit")
let units = unitsSearch.sync()..。我只想得到那些与sectionA有"UnitOfSection“关系的实体,以及具有值false的属性"isExpensive”的实体。
知道如何做到这一点吗?
谢谢+最美好的哀叹
发布于 2018-08-31 16:48:19
这应该是可行的:
let units = Search<Entity>(graph: graph).for(types: "Unit").sync().filter { entity in
(entity["isExpensive"] as? Bool) == false &&
entity.relationship(types: "UnitOfSection").contains(where: { relationship in
relationship.object == sectionA
})
}我们所做的是:
isExpensive = false的筛选实体sectionAhttps://stackoverflow.com/questions/52046390
复制相似问题