@@ -279,38 +279,39 @@ - (id)objectIDForToOneRelationship:(NSRelationshipDescription *)relationship inD
279
279
return [NSNull null ];
280
280
}
281
281
282
- - (NSArray *)objectIDsForToManyRelationship : (NSRelationshipDescription *)relationship forObjectWithID : (NSManagedObjectID *)objectID {
282
+ - (id )objectIDsForToManyRelationship : (NSRelationshipDescription *)relationship forObjectWithID : (NSManagedObjectID *)objectID {
283
+ NSMutableArray *objectIDs = [[NSMutableArray alloc ] init ];
283
284
if ([self sourceDocumentStoresReferenceFieldForRelationship: relationship]) {
284
285
METDocument *document = [self documentForObjectWithID: objectID];
285
- return [self objectIDsForToManyRelationship: relationship inDocument: document];
286
+ [objectIDs addObjectsFromArray: [self objectIDsForToManyRelationship: relationship inDocument: document] ];
286
287
} else {
287
288
NSRelationshipDescription *inverseRelationship = relationship.inverseRelationship ;
288
289
NSString *sourceDocumentID = [self documentKeyForObjectID: objectID].documentID ;
289
290
NSArray *destinationDocuments = [self documentsForEntity: relationship.destinationEntity];
290
291
NSString *fieldName = [self fieldNameForRelationship: inverseRelationship];
291
- NSMutableArray *objectIDs = [[NSMutableArray alloc ] init ];
292
292
for (METDocument *document in destinationDocuments) {
293
293
if ([document[fieldName] isEqual: sourceDocumentID]) {
294
294
[objectIDs addObject: [self objectIDForDocument: document]];
295
295
}
296
296
}
297
- return objectIDs;
298
297
}
298
+ return relationship.isOrdered ? objectIDs : [NSSet setWithArray: objectIDs];
299
299
}
300
300
301
- - (NSArray * )objectIDsForToManyRelationship : (NSRelationshipDescription *)relationship inDocument : (METDocument *)document {
301
+ - (id )objectIDsForToManyRelationship : (NSRelationshipDescription *)relationship inDocument : (METDocument *)document {
302
302
NSString *fieldName = [self fieldNameForRelationship: relationship];
303
303
NSArray *destinationDocumentIDs = document[fieldName];
304
304
if (!destinationDocumentIDs) return nil ;
305
305
NSEntityDescription *destinationEntity = relationship.destinationEntity ;
306
- return [destinationDocumentIDs mappedArrayUsingBlock: ^id (id destinationDocumentID) {
306
+ NSArray *objectIDs = [destinationDocumentIDs mappedArrayUsingBlock: ^id (id destinationDocumentID) {
307
307
METDocument *destinationDocument = [_client.database documentWithKey: [METDocumentKey keyWithCollectionName: [self collectionNameForEntity: destinationEntity] documentID: destinationDocumentID]];
308
308
if (destinationDocument) {
309
309
return [self objectIDForDocument: destinationDocument];
310
310
} else {
311
311
return nil ;
312
312
}
313
313
}];
314
+ return relationship.isOrdered ? objectIDs : [NSSet setWithArray: objectIDs];
314
315
}
315
316
316
317
#pragma mark - Saving
0 commit comments