Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Sep 26, 2016
1 parent 1da6d43 commit 0eda07f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
26 changes: 0 additions & 26 deletions Source/NSManagedObject+Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> || localPrimaryKey is Array<Int> || 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
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions Source/Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 0eda07f

Please sign in to comment.