Skip to content

Commit

Permalink
Merge pull request #481 from batjo/fix/480
Browse files Browse the repository at this point in the history
Fix/480
  • Loading branch information
batjo authored Mar 8, 2018
2 parents 033b12d + 6d6969c commit ad6adc6
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Project.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@
CC9494181F379BE1002167B4 /* 373.json in Resources */ = {isa = PBXBuildFile; fileRef = CC9494171F379BE1002167B4 /* 373.json */; };
CC9494191F379BE1002167B4 /* 373.json in Resources */ = {isa = PBXBuildFile; fileRef = CC9494171F379BE1002167B4 /* 373.json */; };
CC94941A1F379BE1002167B4 /* 373.json in Resources */ = {isa = PBXBuildFile; fileRef = CC9494171F379BE1002167B4 /* 373.json */; };
CCF94957203AE72700C64B80 /* 480.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CCF94955203AE72700C64B80 /* 480.xcdatamodeld */; };
CCF94958203AE72700C64B80 /* 480.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CCF94955203AE72700C64B80 /* 480.xcdatamodeld */; };
CCF94959203AE72700C64B80 /* 480.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CCF94955203AE72700C64B80 /* 480.xcdatamodeld */; };
CCF9495B203AF4AF00C64B80 /* 480.json in Resources */ = {isa = PBXBuildFile; fileRef = CCF9495A203AF4AF00C64B80 /* 480.json */; };
CCF9495C203AF4AF00C64B80 /* 480.json in Resources */ = {isa = PBXBuildFile; fileRef = CCF9495A203AF4AF00C64B80 /* 480.json */; };
CCF9495D203AF4AF00C64B80 /* 480.json in Resources */ = {isa = PBXBuildFile; fileRef = CCF9495A203AF4AF00C64B80 /* 480.json */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -1040,6 +1046,8 @@
CC94940F1F37857F002167B4 /* 375-to-many-speeches.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "375-to-many-speeches.json"; sourceTree = "<group>"; };
CC9494131F379401002167B4 /* 375-to-one-speeches.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "375-to-one-speeches.json"; sourceTree = "<group>"; };
CC9494171F379BE1002167B4 /* 373.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = 373.json; sourceTree = "<group>"; };
CCF94956203AE72700C64B80 /* 480.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = 480.xcdatamodel; sourceTree = "<group>"; };
CCF9495A203AF4AF00C64B80 /* 480.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = 480.json; sourceTree = "<group>"; };
E47FF6201F0002A3004A923A /* Sync+ObjC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Sync+ObjC.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -1338,6 +1346,7 @@
14867D5A1E7AF4D2001D228A /* users_c.json */,
14867D5B1E7AF4D2001D228A /* users_company.json */,
14867D5C1E7AF4D2001D228A /* users_notes.json */,
CCF9495A203AF4AF00C64B80 /* 480.json */,
);
path = JSONs;
sourceTree = "<group>";
Expand Down Expand Up @@ -1393,6 +1402,7 @@
14867DA21E7AF4D2001D228A /* Tests.xcdatamodeld */,
14867DA41E7AF4D2001D228A /* ToOne.xcdatamodeld */,
14867DA61E7AF4D2001D228A /* Unique.xcdatamodeld */,
CCF94955203AE72700C64B80 /* 480.xcdatamodeld */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -1963,6 +1973,7 @@
44E38B112005EE70003E896B /* 422-many-to-many-update-option-initial.json in Resources */,
14867EAB1E7AF4D2001D228A /* story-summarize.json in Resources */,
CC9494181F379BE1002167B4 /* 373.json in Resources */,
CCF9495B203AF4AF00C64B80 /* 480.json in Resources */,
14867E811E7AF4D2001D228A /* custom_relationship_key_to_one.json in Resources */,
CC9494101F37857F002167B4 /* 375-to-many-speeches.json in Resources */,
14867E9C1E7AF4D2001D228A /* operation-types-users-a.json in Resources */,
Expand Down Expand Up @@ -2072,6 +2083,7 @@
14867EAC1E7AF4D2001D228A /* story-summarize.json in Resources */,
CC9494191F379BE1002167B4 /* 373.json in Resources */,
14867E821E7AF4D2001D228A /* custom_relationship_key_to_one.json in Resources */,
CCF9495C203AF4AF00C64B80 /* 480.json in Resources */,
CC9494111F37857F002167B4 /* 375-to-many-speeches.json in Resources */,
14867E9D1E7AF4D2001D228A /* operation-types-users-a.json in Resources */,
14867E731E7AF4D2001D228A /* bug-257.json in Resources */,
Expand Down Expand Up @@ -2181,6 +2193,7 @@
14867EAD1E7AF4D2001D228A /* story-summarize.json in Resources */,
CC94941A1F379BE1002167B4 /* 373.json in Resources */,
14867E831E7AF4D2001D228A /* custom_relationship_key_to_one.json in Resources */,
CCF9495D203AF4AF00C64B80 /* 480.json in Resources */,
CC9494121F37857F002167B4 /* 375-to-many-speeches.json in Resources */,
14867E9E1E7AF4D2001D228A /* operation-types-users-a.json in Resources */,
14867E741E7AF4D2001D228A /* bug-257.json in Resources */,
Expand Down Expand Up @@ -2357,6 +2370,7 @@
445851D01E87BAF50025434E /* 129.xcdatamodeld in Sources */,
14867ED21E7AF4D2001D228A /* 151-ordered-many-to-many.xcdatamodeld in Sources */,
14867F4A1E7AF4D2001D228A /* SyncTests.swift in Sources */,
CCF94957203AE72700C64B80 /* 480.xcdatamodeld in Sources */,
14867EF31E7AF4D2001D228A /* 265.xcdatamodeld in Sources */,
14867EFC1E7AF4D2001D228A /* 283.xcdatamodeld in Sources */,
445851E21E87BAF60025434E /* SyncDictionaryTests.m in Sources */,
Expand Down Expand Up @@ -2455,6 +2469,7 @@
445851D11E87BAF50025434E /* 129.xcdatamodeld in Sources */,
14867ED31E7AF4D2001D228A /* 151-ordered-many-to-many.xcdatamodeld in Sources */,
14867F4B1E7AF4D2001D228A /* SyncTests.swift in Sources */,
CCF94958203AE72700C64B80 /* 480.xcdatamodeld in Sources */,
14867EF41E7AF4D2001D228A /* 265.xcdatamodeld in Sources */,
14867EFD1E7AF4D2001D228A /* 283.xcdatamodeld in Sources */,
445851E31E87BAF60025434E /* SyncDictionaryTests.m in Sources */,
Expand Down Expand Up @@ -2553,6 +2568,7 @@
445851D21E87BAF50025434E /* 129.xcdatamodeld in Sources */,
14867ED41E7AF4D2001D228A /* 151-ordered-many-to-many.xcdatamodeld in Sources */,
14867F4C1E7AF4D2001D228A /* SyncTests.swift in Sources */,
CCF94959203AE72700C64B80 /* 480.xcdatamodeld in Sources */,
14867EF51E7AF4D2001D228A /* 265.xcdatamodeld in Sources */,
14867EFE1E7AF4D2001D228A /* 283.xcdatamodeld in Sources */,
445851E41E87BAF60025434E /* SyncDictionaryTests.m in Sources */,
Expand Down Expand Up @@ -3779,6 +3795,16 @@
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
};
CCF94955203AE72700C64B80 /* 480.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
CCF94956203AE72700C64B80 /* 480.xcdatamodel */,
);
currentVersion = CCF94956203AE72700C64B80 /* 480.xcdatamodel */;
path = 480.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
};
/* End XCVersionGroup section */
};
rootObject = 146D728B1AB782920058798C /* Project object */;
Expand Down
2 changes: 1 addition & 1 deletion Source/Sync/NSManagedObject+Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ extension NSManagedObject {
childOperations.remove(.delete)
}

if let entity = NSEntityDescription.entity(forEntityName: childEntityName, in: context), childrenIDs.count > 0 {
if let entity = NSEntityDescription.entity(forEntityName: childEntityName, in: context) {
if manyToMany {
childPredicate = NSPredicate(format: "ANY %K IN %@", entity.sync_localPrimaryKey(), childrenIDs)
} else {
Expand Down
37 changes: 37 additions & 0 deletions Tests/Sync/JSONs/480.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"id" : 450639,
"history_items" : [
{
"id" : 1434417
},
{
"id" : 1436608
},
{
"id" : 1436612
}
]
},
{
"id" : 3497534,
"history_items" : [
{
"id" : 1434418
},
{
"id" : 1436609
},
{
"id" : 1436613
}
]
},
{
"id" : 3497535,
"history_items" : [

]
}
]

28 changes: 28 additions & 0 deletions Tests/Sync/Models/480.xcdatamodeld/480.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="13772" systemVersion="17D47" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="HistoryItem" representedClassName="HistoryItem" syncable="YES" codeGenerationType="class">
<attribute name="historyItemID" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES">
<userInfo>
<entry key="sync.isPrimaryKey" value="true"/>
<entry key="sync.remoteKey" value="id"/>
</userInfo>
</attribute>
<relationship name="report" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Report" inverseName="historyItems" inverseEntity="Report" syncable="YES"/>
<userInfo>
<entry key="key" value="value"/>
</userInfo>
</entity>
<entity name="Report" representedClassName="Report" syncable="YES" codeGenerationType="class">
<attribute name="reportID" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES">
<userInfo>
<entry key="sync.isPrimaryKey" value="true"/>
<entry key="sync.remoteKey" value="id"/>
</userInfo>
</attribute>
<relationship name="historyItems" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="HistoryItem" inverseName="report" inverseEntity="HistoryItem" syncable="YES"/>
</entity>
<elements>
<element name="Report" positionX="-63" positionY="-18" width="128" height="75"/>
<element name="HistoryItem" positionX="-54" positionY="-9" width="128" height="75"/>
</elements>
</model>
12 changes: 12 additions & 0 deletions Tests/Sync/SyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1722,4 +1722,16 @@ class SyncTests: XCTestCase {

dataStack.drop()
}

func test480() {
let dataStack = Helper.dataStackWithModelName("480")

let data = Helper.objectsFromJSON("480.json") as! [[String: Any]]
dataStack.sync(data, inEntityNamed: "Report", completion: nil)

XCTAssertEqual(Helper.countForEntity("Report", inContext: dataStack.mainContext), 3)
XCTAssertEqual(Helper.countForEntity("HistoryItem", inContext: dataStack.mainContext), 6)

dataStack.drop()
}
}

0 comments on commit ad6adc6

Please sign in to comment.