Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Content of Child Managed Object Context Always the Same with Content of it's Parent?

How to update child managed object context so it has the same data with parent?

As far as I know, when saving, child only goes one step, namely to parents. Yet when fetching fetch always go really deep all the way to the parent and persistent store. So I expect things will be the same.

Yet it's not.

I have a managed object context that is parent of all other managed object context.

One child change data and save. The parent is also changed. I do executeFetchRequest on parent and I see that the data change.

However, some child of the parents still use old data. Same object id same data. Somehow the value of the property remain the same.

How to tell the child to reload fresh data from the parent?

To be more exact

Say P is the parent

Say it has C1 C2 C3 as child

Then C1 changes data and commit. The change is propagated to P. However, executing executeFetchRequest at C2 and C3 still shows old data.

What gives?

For example, when I check for the imageBlob property, this is what I get:

Child:

2013-02-05 13:57:42.865 BadgerNew[78801:c07] imageBlob: <UIImage: 0x89c3c50>
2013-02-05 13:57:42.866 BadgerNew[78801:c07] imageBlob: <null>
2013-02-05 13:57:42.866 BadgerNew[78801:c07] imageBlob: <null>
2013-02-05 13:57:42.866 BadgerNew[78801:c07] imageBlob: <null>

Parent:

2013-02-05 13:57:42.868 BadgerNew[78801:c07] imageBlob: <UIImage: 0x114af650>
2013-02-05 13:57:42.868 BadgerNew[78801:c07] imageBlob: <UIImage: 0x8e492e0>
2013-02-05 13:57:42.868 BadgerNew[78801:c07] imageBlob: <UIImage: 0x114c79b0>
2013-02-05 13:57:42.869 BadgerNew[78801:c07] imageBlob: <UIImage: 0xa8c76e0>

Here is a more comprehensive version why I jot down the moc, the parent moc, the blob, the URL and the object ID. Child:

In particular I want the mainqueue managedobject context to be another child of the parent rather than the parent of all other managedObjectContext. On the other hand, I also want the mainQueue Managed object context to have uptodate information. I wonder what the standard solution be.

like image 860
user4951 Avatar asked Feb 04 '13 13:02

user4951


1 Answers

The child has invalid existing references. If you want the siblings to be in sync after parent save, you must invalidate the children with reset.

After calling reset, all the receiver's managed objects are “forgotten.” If you use this method, you should ensure that you also discard references to any managed objects fetched using the receiver, since they will be invalid afterwards.

You can also use refreshObject:mergeChanges: on the individual objects changed on all the child contexts when saving the parent context if you want finer control on changed objects in the child contexts.

like image 151
Fruity Geek Avatar answered Nov 08 '22 12:11

Fruity Geek