Originally created by @TheJustikar on GitHub (Dec 16, 2020).
I am trying to fetch all entities from the class Match whose Discipline is contained in an array of disciplines.
Here is the code for fetching that is not working:
let disciplines: [Discipline] = ...
try CoreStoreDefaults.dataStack.fetchAll(From<Match>().where(Where<Match>(\.$discipline, isMemberOf: disciplines)))
The compiler error I am getting is:
Key path value type 'FieldContainer<Match>.Relationship<Discipline?>' cannot be converted to contextual type 'RelationshipContainer<Match>.ToOne<Discipline>'
Here is the Match 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]
}
Here is the Disciple class:
final class Discipline: CoreStoreObject {
@Field .Stored("name")
var name: String = ""
@Field .Relationship("matches", inverse: \.$discipline)
var matches: [Match]
}
What exactly am I doing wrong here?
Originally created by @TheJustikar on GitHub (Dec 16, 2020).
I am trying to fetch all entities from the class `Match` whose `Discipline` is contained in an array of disciplines.
Here is the code for fetching that is not working:
```
let disciplines: [Discipline] = ...
try CoreStoreDefaults.dataStack.fetchAll(From<Match>().where(Where<Match>(\.$discipline, isMemberOf: disciplines)))
```
The compiler error I am getting is:
```
Key path value type 'FieldContainer<Match>.Relationship<Discipline?>' cannot be converted to contextual type 'RelationshipContainer<Match>.ToOne<Discipline>'
```
Here is the Match 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]
}
```
Here is the Disciple class:
```
final class Discipline: CoreStoreObject {
@Field .Stored("name")
var name: String = ""
@Field .Relationship("matches", inverse: \.$discipline)
var matches: [Match]
}
```
What exactly am I doing wrong here?
@TheJustikar commented on GitHub (Dec 16, 2020):
I also asked this question on stackoverflow:
https://stackoverflow.com/questions/65167443/corestore-fetch-where-relationship-is-contained-in-array
@TheJustikar Hi, thanks for reporting this. It looks like there's a missing overload within the Where operators.
I'll fix this in a coming update, but for now you can workaround it using String key paths:
@JohnEstropia commented on GitHub (Dec 16, 2020):
@TheJustikar Hi, thanks for reporting this. It looks like there's a missing overload within the `Where` operators.
I'll fix this in a coming update, but for now you can workaround it using `String` key paths:
```swift
try CoreStoreDefaults.dataStack.fetchAll(
From<Match>()
.where(.init(String(keyPath: \Match.$discipline), isMemberOf: disciplines))
)
```
@JohnEstropia commented on GitHub (Dec 16, 2020):
You can also try the "matches" operator:
```swift
try CoreStoreDefaults.dataStack.fetchAll(
From<Match>()
.where(disciplines ~= \.$discipline)
)
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @TheJustikar on GitHub (Dec 16, 2020).
I am trying to fetch all entities from the class
MatchwhoseDisciplineis contained in an array of disciplines.Here is the code for fetching that is not working:
The compiler error I am getting is:
Here is the Match class:
Here is the Disciple class:
What exactly am I doing wrong here?
@TheJustikar commented on GitHub (Dec 16, 2020):
I also asked this question on stackoverflow:
https://stackoverflow.com/questions/65167443/corestore-fetch-where-relationship-is-contained-in-array
@JohnEstropia commented on GitHub (Dec 16, 2020):
@TheJustikar Hi, thanks for reporting this. It looks like there's a missing overload within the
Whereoperators.I'll fix this in a coming update, but for now you can workaround it using
Stringkey paths:@JohnEstropia commented on GitHub (Dec 16, 2020):
You can also try the "matches" operator:
@Tykhonkov commented on GitHub (Dec 5, 2022):
would be great to add this example in the documentation