mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Fix bug saving authors in database.
This commit is contained in:
parent
9a26df89d1
commit
b264305cfa
@ -137,12 +137,27 @@ private extension DatabaseLookupTable {
|
|||||||
|
|
||||||
func uniqueRelatedObjects(with objects: [DatabaseObject]) -> [DatabaseObject] {
|
func uniqueRelatedObjects(with objects: [DatabaseObject]) -> [DatabaseObject] {
|
||||||
|
|
||||||
// All of our objects that conform to DatabaseObject are Hashable.
|
var relatedObjectIDs = Set<String>()
|
||||||
// If that’s ever not true, this will crash when run from Xcode.
|
var relatedObjectsUniqueArray = [DatabaseObject]()
|
||||||
let objectSet = Set(objects as! [AnyHashable])
|
|
||||||
return Array(objectSet) as! [DatabaseObject]
|
for object in objects {
|
||||||
|
guard let relatedObjects = object.relatedObjectsWithName(relationshipName) else {
|
||||||
|
assertionFailure("uniqueRelatedObjects: expected every object to have related objects.")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for relatedObject in relatedObjects {
|
||||||
|
let databaseID = relatedObject.databaseID
|
||||||
|
if !relatedObjectIDs.contains(databaseID) {
|
||||||
|
relatedObjectIDs.insert(databaseID)
|
||||||
|
relatedObjectsUniqueArray.append(relatedObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(relatedObjectIDs.count == relatedObjectsUniqueArray.count)
|
||||||
|
return relatedObjectsUniqueArray
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncRelatedObjectsAndLookupTable(_ object: DatabaseObject, _ lookupTable: RelatedObjectIDsMap, _ database: FMDatabase) {
|
func syncRelatedObjectsAndLookupTable(_ object: DatabaseObject, _ lookupTable: RelatedObjectIDsMap, _ database: FMDatabase) {
|
||||||
|
|
||||||
guard let relatedObjects = object.relatedObjectsWithName(relationshipName) else {
|
guard let relatedObjects = object.relatedObjectsWithName(relationshipName) else {
|
||||||
|
Loading…
Reference in New Issue
Block a user