On 2009 May 06, at 02:13, Alexander Spohr wrote:

The MOC knows the objects is deleted. If you try to refetch it, the MOC has to clear all attributes because it does not exist anymore (in the MOCs view of the database). Is the primary key still the same? If it is not null now as well...

Well, although we're not supposed to worry about what Core Data does under the hood, I presume the primary key is the objectID. Adding some statements to log it, i.e.

  [[[foo objectID] URIRepresentation] absoluteString]

I see that this value never changes.

In my real app, the object has more than one attribute, not just 'name', and those attributes become nil too. So it seems that all attributes except the objectID, which may be a "primary key", get nilled.

You should not re-fetch a dirty MOC.

Sounds logical, but I cannot find any indication of that in "Core Data Programming Guide" > "Fetching Managed Objects"

Save its changes first.

OK, I just added a [moc save:NULL] with some more logging. Result: Executing the -save: wipes out the object attribute the same as executing the fetch does. By the way, the fetch returns empty, with or without the -save:. This is as expected.

Sure, your object will then be lost. But a deletion should exactly do that. To revive an object from the dead is a strange concept (just in my opinion).

Yes, I agree that it's pushing the envelope. But where's the documentation that says I can't?

Try to either rearrange your delete/insert to just rehang the object into another parent, create a new object (you should not depend on the primary key anyway) or _maybe_ you could use a second MOC to fetch and insert. The latter depends on your projects structure.

I can think of several ways to work around this, but I want to understand what the problem is -- what documented rule I have broken.
I may have repeated this mistake elsewhere!

In any case using multiple MOCs for different jobs is a good idea.

Accessing the same store? I always thought that was a bad idea, but I'll give it some thought.

Thanks, atze.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to