Search code examples
core-datarestkitnsfetchedresultscontrollerrestkit-0.20

If a mapping for NSManagedObject is using identificationAttributes then NSFetchedResultsController does not update


Can anyone confirm my experience which shows the NSFetchedResultsController is not performing fetches if the mapping for a nsmanagedobject contains identificationAttributes and just attribute's value of this object is being updated from JSON?

Another issue I have with Restkit is the behavior of this "identificationAttributes" feature. If Restkit is going to map json data to such a (unique) core data object then it looks if there is already an existing instance of this nsmanagedobject. But it seems this instance is being searched globaly, that is, there can be only one and single instance of this specific nsmanagedobject in the store with this specific identification attribute. I would expect to have a single instance not per store, but per owner (a parent owning relationship to this nsmanagedobject).

So this structure I would expect (id is the identification attribute value):

OwnerA/OwnerB and Owned are subclasses of NSManagedObject. All mappings are using identificationAttributes for all classes to keep them unique.

Response comes with: OwnerA:

  • -->relatioship to Owned(id == X)
  • -->relatioship to Owned(id == Y)
  • Second response comes with: OwnerB:

  • -->relatioship to Owned(id == X)
  • -->relatioship to Owned(id == Z)
  • But instead I get from Restkit this structure:

    Response comes with: OwnerA:

  • -->relatioship to Owned(id == X)
  • -->relatioship to Owned(id == Y)
  • Second response comes with: OwnerB:

  • -->relatioship to Owned(id == X)
  • -->relatioship to Owned(id == Z)
  • but the OwnerA looses its relationship to Owned(id==X)

    OwnerA:

  • -->relatioship to Owned(id == X)
  • -->relatioship to Owned(id == Y)
  • as the only single instance of Owned with this id==X is defined by the relationship from OwnerB.

    So there is only single instance of Owned with id attribute X. But it would be way better if this uniqueness was dictated per owner not global.

    Furthermore update of Owned with the id attribute X is not registered by NSFetchedResultsController event if the predicate is using statements with Owned.attributeValue == ... NSPredicate is useless for detecting changes in relationships. That I know, but it also does not detect changes in nsmanagedobjects if such an object is using identificationAttributes.

    Thank you for a comment.


    Solution

  • Yes, the identification is global to the context (so the data store), not on a per 'owner' (relationship) basis (you have no way to specify what the owner might be).

    If you wanted to manage things with some owner you could use nesting in your JSON to define the unique owner and the relationship contents it has.

    Note also that you can have more than one identification attribute (but that the identification attribute list on each mapping for the same entity must be the same or strange things will happen). So, you can emulate ownership identity by copying the owner identity onto other objects and using that attribute in the identification list. You would need to copy the identity to the other object, you couldn't reference it through a relationship.

    The identification attribute is completely unrelated to the FRC and what it is observing. I'm not 100% clear on what you're seeing, but it must be related to either / and / or relationship contents or the creation of new objects that you aren't expecting.