From 0eda07fde346113ff5041c4e0d7e64725ad996fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= Date: Tue, 27 Sep 2016 00:06:32 +0200 Subject: [PATCH] Fix failing test --- Source/NSManagedObject+Sync.swift | 26 -------------------------- Source/Sync.swift | 5 +++-- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Source/NSManagedObject+Sync.swift b/Source/NSManagedObject+Sync.swift index b5c29907..667be685 100644 --- a/Source/NSManagedObject+Sync.swift +++ b/Source/NSManagedObject+Sync.swift @@ -34,31 +34,6 @@ public extension NSManagedObject { func sync_fillWithDictionary(dictionary: [String : AnyObject], parent: NSManagedObject?, parentRelationship: NSRelationshipDescription?, dataStack: DATAStack, operations: DATAFilter.Operation) { hyp_fillWithDictionary(dictionary) - for relationship in entity.sync_relationships() { - let suffix = relationship.toMany ? "_ids" : "_id" - let constructedKeyName = relationship.name.hyp_remoteString() + suffix - let keyName = relationship.userInfo?[SYNCCustomRemoteKey] as? String ?? constructedKeyName - - if relationship.toMany { - if let localPrimaryKey = dictionary[keyName] where localPrimaryKey is Array || localPrimaryKey is Array || localPrimaryKey is NSNull { - sync_toManyRelationshipUsingIDsInsteadOfDictionary(relationship, localPrimaryKey: localPrimaryKey) - } else { - sync_toManyRelationship(relationship, dictionary: dictionary, parent: parent, parentRelationship: parentRelationship, dataStack: dataStack, operations: operations) - } - } else if let parent = parent where !parent.isEqual(valueForKey(relationship.name)) && relationship.destinationEntity?.name == parent.entity.name || relationship.destinationEntity?.name == parent.entity.superentity?.name { - setValue(parent, forKey: relationship.name) - } else if let localPrimaryKey = dictionary[keyName] where localPrimaryKey is NSString || localPrimaryKey is NSNumber || localPrimaryKey is NSNull { - sync_toOneRelationshipUsingIDInsteadOfDictionary(relationship, localPrimaryKey: localPrimaryKey, dataStack: dataStack) - } else { - sync_toOneRelationship(relationship, dictionary: dictionary, dataStack: dataStack, operations: operations) - } - } - } - - /* - func sync_fillWithDictionary(dictionary: [String : AnyObject], parent: NSManagedObject?, parentRelationship: NSRelationshipDescription?, dataStack: DATAStack, operations: DATAFilter.Operation) { - hyp_fillWithDictionary(dictionary) - for relationship in entity.sync_relationships() { let suffix = relationship.toMany ? "_ids" : "_id" let constructedKeyName = relationship.name.hyp_remoteString() + suffix @@ -97,7 +72,6 @@ public extension NSManagedObject { } } } - */ /** Syncs relationships where only the ids are present, for example if your model is: User <<->> Tags (a user has many tags and a tag belongs to many users), diff --git a/Source/Sync.swift b/Source/Sync.swift index 504b3924..38681497 100644 --- a/Source/Sync.swift +++ b/Source/Sync.swift @@ -184,11 +184,12 @@ import TestCheck let relationships = entity.relationshipsWithDestinationEntity(parent.entity) var predicate: NSPredicate? = nil - if let firstRelationship = relationships.first { + let firstRelationship = relationships.first + if let firstRelationship = firstRelationship { predicate = NSPredicate(format: "%K = %@", firstRelationship.name, safeParent) } - self.changes(changes, inEntityNamed: entityName, predicate: predicate, parent: safeParent, parentRelationship: nil, inContext: backgroundContext, dataStack: dataStack, operations: .All, completion: completion) + self.changes(changes, inEntityNamed: entityName, predicate: predicate, parent: safeParent, parentRelationship: firstRelationship?.inverseRelationship, inContext: backgroundContext, dataStack: dataStack, operations: .All, completion: completion) } }