diff --git a/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj b/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj index ab2506259..e2941a807 100755 --- a/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj +++ b/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj @@ -565,6 +565,7 @@ INFOPLIST_FILE = RSDatabase/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=25"; PRODUCT_BUNDLE_IDENTIFIER = com.ranchero.RSDatabase; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -585,6 +586,7 @@ INFOPLIST_FILE = RSDatabase/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=25"; PRODUCT_BUNDLE_IDENTIFIER = com.ranchero.RSDatabase; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/Frameworks/RSDatabase/RSDatabase/DatabaseLookupTable.swift b/Frameworks/RSDatabase/RSDatabase/DatabaseLookupTable.swift index 928aae0d0..ab4f6ef25 100644 --- a/Frameworks/RSDatabase/RSDatabase/DatabaseLookupTable.swift +++ b/Frameworks/RSDatabase/RSDatabase/DatabaseLookupTable.swift @@ -38,22 +38,27 @@ public final class DatabaseLookupTable { attachRelationshipsUsingLookupTable(to: objects, lookupTable: lookupTable, database: database) } - public func saveRelationships(for objects: [DatabaseObject], relationshipName: String, database: FMDatabase) { + public func saveRelationships(for objects: [DatabaseObject], database: FMDatabase) { var objectsWithNoRelationships = [DatabaseObject]() var objectsWithRelationships = [DatabaseObject]() - objects.forEach { (object) - if let relatedObjects = object.relatedObjectsWithName(relationshipsName) + for object in objects { + if let relatedObjects = object.relatedObjectsWithName(relationshipName), !relatedObjects.isEmpty { + objectsWithRelationships += [object] + } + else { + objectsWithNoRelationships += [object] + } } - + + removeRelationships(for: objectsWithNoRelationships, database: database) } - } private extension DatabaseLookupTable { - func removeRelationships(for objects: [DatabaseObject], relationshipName: String, database: FMDatabase) { + func removeRelationships(for objects: [DatabaseObject], database: FMDatabase) { removeLookupsForForeignIDs(objects.databaseIDs(), database) } @@ -196,7 +201,7 @@ struct LookupValue: Hashable { self.primaryID = primaryID self.foreignID = foreignID - self.hashValue = "\(primaryID)\(foreignID)".hashValue + self.hashValue = (primaryID + foreignID).hashValue } static public func ==(lhs: LookupValue, rhs: LookupValue) -> Bool {