Reputation: 1609
Here's a simplified look for my model:
Is there any way to use NSFetchedResultsController to fetch all Users that are 'Synced' and whose all media are 'Uploaded'? It would have to update its content also when 'Media' status is changed so that new User should be fetched. I've heard NSFetchedResultsController doesn't work well with such complex fetch requests.
Upvotes: 1
Views: 68
Reputation: 80265
I agree that the user should have another status flag (or use the synced status flag). You can update this at a central point by overriding the setter in the media object.
-(void)setStatus:(MediaStatus)value {
[self willChangeValueForKey:@"status"];
[self setPrimitiveStatus:value];
[self didChangeValueForKey:@"status"];
// get status of other media objects
NSSet *objects = self.objectx.user.objects;
NSSet *updatingObjects =
[objects filteredSetUsingPredicate:
[NSPredicate predicatesWithFormat:@"media.status = %@", kUpdatingStatus]];
self.objectx.user.updating =
updatingObjects.count ? kUpdatingStatus : kUpdatedStatus;
}
Still, an appropriate FRC predicate should also work. E.g., to only show updated users, something along the lines of
[NSPredicate predicateWithFormat:@"any objectx.media.status = $@", kUpdatedStatus]
Upvotes: 1
Reputation:
It would be more practical to model the fetch by denormalizing the data. You can add a 'status' Boolean to User indicating whether all their Media is uploaded.
This would be much more efficient than having to aggregate the status of each object's model.
Upvotes: 0