CoreStore:获取关系包含在数组中的位置

CoreStore: Fetch where relationship is contained in array

我正在尝试从 class Match 中获取所有实体,其 Discipline 包含在学科数组中。

这是无法正常工作的抓取代码:

let disciplines: [Discipline] = ...
try CoreStoreDefaults.dataStack.fetchAll(From<Match>().where(Where<Match>(\.$discipline, isMemberOf: disciplines)))

我得到的编译器错误是:

Key path value type 'FieldContainer<Match>.Relationship<Discipline?>' cannot be converted to contextual type 'RelationshipContainer<Match>.ToOne<Discipline>'

这是比赛 class:

final class Match: CoreStoreObject {
    @Field .Stored("date", dynamicInitialValue: { Date() })
    var date: Date

    @Field .Stored("winnersPoints")
    var winnersPoints: Double = 0

    @Field .Stored("loosersPoints")
    var loosersPoints: Double = 0

    @Field .Relationship("discipline")
    var discipline: Discipline?

    @Field .Relationship("winners")
    var winners: [Player]

    @Field .Relationship("loosers")
    var loosers: [Player]
}

弟子来了class:

final class Discipline: CoreStoreObject {
    @Field .Stored("name")
    var name: String = ""

    @Field .Relationship("matches", inverse: \.$discipline)
    var matches: [Match]
}

我到底做错了什么?

我也在 CoreStore issues section 上回答了你的问题。

Where 初始化器中缺少重载,我将在即将发布的更新中添加它,但您也可以将 ~= 运算符用作 shorthand 语法:

try CoreStoreDefaults.dataStack.fetchAll(
    From<Match>()
        .where(disciplines ~= \.$discipline)
)