Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.

Commit 7797a53

Browse files
committed
Properly handle unordered relationship in METIncrementalStore
1 parent 3022aae commit 7797a53

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Meteor/METIncrementalStore.m

+7-6
Original file line numberDiff line numberDiff line change
@@ -279,38 +279,39 @@ - (id)objectIDForToOneRelationship:(NSRelationshipDescription *)relationship inD
279279
return [NSNull null];
280280
}
281281

282-
- (NSArray *)objectIDsForToManyRelationship:(NSRelationshipDescription *)relationship forObjectWithID:(NSManagedObjectID *)objectID {
282+
- (id)objectIDsForToManyRelationship:(NSRelationshipDescription *)relationship forObjectWithID:(NSManagedObjectID *)objectID {
283+
NSMutableArray *objectIDs = [[NSMutableArray alloc] init];
283284
if ([self sourceDocumentStoresReferenceFieldForRelationship:relationship]) {
284285
METDocument *document = [self documentForObjectWithID:objectID];
285-
return [self objectIDsForToManyRelationship:relationship inDocument:document];
286+
[objectIDs addObjectsFromArray:[self objectIDsForToManyRelationship:relationship inDocument:document]];
286287
} else {
287288
NSRelationshipDescription *inverseRelationship = relationship.inverseRelationship;
288289
NSString *sourceDocumentID = [self documentKeyForObjectID:objectID].documentID;
289290
NSArray *destinationDocuments = [self documentsForEntity:relationship.destinationEntity];
290291
NSString *fieldName = [self fieldNameForRelationship:inverseRelationship];
291-
NSMutableArray *objectIDs = [[NSMutableArray alloc] init];
292292
for (METDocument *document in destinationDocuments) {
293293
if ([document[fieldName] isEqual:sourceDocumentID]) {
294294
[objectIDs addObject:[self objectIDForDocument:document]];
295295
}
296296
}
297-
return objectIDs;
298297
}
298+
return relationship.isOrdered ? objectIDs : [NSSet setWithArray:objectIDs];
299299
}
300300

301-
- (NSArray *)objectIDsForToManyRelationship:(NSRelationshipDescription *)relationship inDocument:(METDocument *)document {
301+
- (id)objectIDsForToManyRelationship:(NSRelationshipDescription *)relationship inDocument:(METDocument *)document {
302302
NSString *fieldName = [self fieldNameForRelationship:relationship];
303303
NSArray *destinationDocumentIDs = document[fieldName];
304304
if (!destinationDocumentIDs) return nil;
305305
NSEntityDescription *destinationEntity = relationship.destinationEntity;
306-
return [destinationDocumentIDs mappedArrayUsingBlock:^id(id destinationDocumentID) {
306+
NSArray *objectIDs = [destinationDocumentIDs mappedArrayUsingBlock:^id(id destinationDocumentID) {
307307
METDocument *destinationDocument = [_client.database documentWithKey:[METDocumentKey keyWithCollectionName:[self collectionNameForEntity:destinationEntity] documentID:destinationDocumentID]];
308308
if (destinationDocument) {
309309
return [self objectIDForDocument:destinationDocument];
310310
} else {
311311
return nil;
312312
}
313313
}];
314+
return relationship.isOrdered ? objectIDs : [NSSet setWithArray:objectIDs];
314315
}
315316

316317
#pragma mark - Saving

0 commit comments

Comments
 (0)