mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-24 08:41:31 +01:00
Make progress on relationships.
This commit is contained in:
parent
570d70d8fe
commit
4223808c74
@ -78,8 +78,8 @@ private extension AuthorsTable {
|
||||
|
||||
func fetchAuthorsForArticleIDs(_ articleIDs: Set<String>, _ database: FMDatabase) -> [String: Set<Author>]? {
|
||||
|
||||
let lookupValueDictionary = authorsLookupTable.fetchLookupTableDictionary(articleIDs, database)
|
||||
let authorIDs = Set(lookupValues.map { $0.primaryID })
|
||||
let lookupTableDictionary = authorsLookupTable.fetchLookupTableDictionary(articleIDs, database)
|
||||
let authorIDs = authorsLookupTable.primaryIDsInLookupTableDictionary(lookupTableDictionary)
|
||||
if authorIDs.isEmpty {
|
||||
return nil
|
||||
}
|
||||
|
@ -64,6 +64,33 @@ public final class LookupTable {
|
||||
return lookupTableDictionary(with: lookupValues)
|
||||
}
|
||||
|
||||
public func attachRelationships<T,U>(_ objects: [T], idKeyPath: KeyPath<T,String>, relationshipKeyPath: KeyPath<T,[U]>, table: DatabaseTable, lookupTableDictionary: LookupTableDictionary, database: FMDatabase) {
|
||||
|
||||
let primaryIDs = primaryIDsInLookupTableDictionary(lookupTableDictionary)
|
||||
let relatedObjects = table.fetchObjectsWithIDs(primaryIDs, database)
|
||||
|
||||
for object in objects {
|
||||
let identifier = object[keyPath: idKeyPath]
|
||||
if let lookupValues = lookupTableDictionary[identifier] {
|
||||
let relatedObjects = lookupValues.flatMap{ (lookupValue) -> U? in
|
||||
<#code#>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func primaryIDsInLookupTableDictionary(_ lookupTableDictionary: LookupTableDictionary) -> Set<String> {
|
||||
|
||||
var primaryIDs = Set<String>()
|
||||
|
||||
for (_, lookupValues) in lookupTableDictionary {
|
||||
primaryIDs.formUnion(lookupValues.primaryIDs())
|
||||
}
|
||||
|
||||
return primaryIDs
|
||||
}
|
||||
|
||||
public func removeLookupsForForeignIDs(_ foreignIDs: Set<String>, _ database: FMDatabase) {
|
||||
|
||||
let foreignIDsToRemove = foreignIDs.subtracting(foreignIDsWithNoRelationship)
|
||||
@ -156,3 +183,10 @@ public struct LookupValue: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
private extension Set where Element == LookupValue {
|
||||
|
||||
func primaryIDs() -> Set<String> {
|
||||
|
||||
return Set(map { $0.primaryID })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user