it uses propertiesToGroupBy and havingPredicate but I can not find any mechanism in CoreStore to use for it.
Does exist any way to use it ?
Originally created by @vitt0re on GitHub (Jun 2, 2020).
Hello
I need to migrate the code like one below to CoreStore
```
let dupeFetch: NSFetchRequest<NSFetchRequestResult> = StopEntity.fetchRequest()
let nameExpr = NSExpression(forKeyPath: "name")
let countExpr = NSExpressionDescription()
let countVariableExpr = NSExpression(forVariable: "count")
countExpr.name = "count"
countExpr.expression = NSExpression(forFunction: "count:", arguments: [nameExpr])
countExpr.expressionResultType = .integer64AttributeType
dupeFetch.resultType = .dictionaryResultType
dupeFetch.propertiesToGroupBy = ["latitude", "longitude"]
dupeFetch.propertiesToFetch = ["latitude", "longitude", countExpr]
dupeFetch.returnsObjectsAsFaults = false
dupeFetch.havingPredicate = NSPredicate(format: "%@ > 1", countVariableExpr)
var dupes = [Any]()
do {
dupes = try dataManager.context.fetch(dupeFetch)
} catch {
print(error.localizedDescription)
}
```
it uses **propertiesToGroupBy** and **havingPredicate** but I can not find any mechanism in CoreStore to use for it.
Does exist any way to use it ?
Thanks for raising this. I'll consider adding this extension to GroupBy clauses.
@JohnEstropia commented on GitHub (Jun 3, 2020):
There's no default utility for it yet, but you can also use `GroupBy` in tandem with `Tweak` to achieve the same effect:
```swift
let countKey = "numberOfDuplicates"
let latitudeKey = "lat"
let longitudeKey = "long"
let dupes: NSDictionary = dataStack.fetchAll(
From<StopEntity>()
.select(
NSDictionary.self,
.count(\.name, as: countKey),
.attribute(\.latitude, as: latitudeKey),
.attribute(\.longitude, as: longitudeKey)
)
.groupBy(latitudeKey, longitudeKey)
.tweak(
{ $0.havingPredicate = Where<StopEntity>("%K > %@", countKey, 1).predicate }
)
)
```
Thanks for raising this. I'll consider adding this extension to `GroupBy` clauses.
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 @vitt0re on GitHub (Jun 2, 2020).
Hello
I need to migrate the code like one below to CoreStore
it uses propertiesToGroupBy and havingPredicate but I can not find any mechanism in CoreStore to use for it.
Does exist any way to use it ?
@JohnEstropia commented on GitHub (Jun 3, 2020):
There's no default utility for it yet, but you can also use
GroupByin tandem withTweakto achieve the same effect:Thanks for raising this. I'll consider adding this extension to
GroupByclauses.