Re: Core Data: objectRegisteredForID: vs objectWithID: question / Cross store relationship problem
Re: Core Data: objectRegisteredForID: vs objectWithID: question / Cross store relationship problem
- Subject: Re: Core Data: objectRegisteredForID: vs objectWithID: question / Cross store relationship problem
- From: John Bishop <email@hidden>
- Date: Mon, 27 Mar 2006 21:49:27 -0600
Usually, if you're using cross-store relationships, at least one side of the
relationship will have to do a real fetch - Check out the teacher/courses
relationship (one-to-many cross-store) and the students/courses relationship
(many-to-many) illustrated in the iClass sample code. There's an example in
there of a fetched property "courses" based on the URIRepresentation "teacher"
in the cross-store entity.
If you foresee (and apparently you do) that objects at the far end of a
cross-store relationship might be missing, then you're going to have to adapt
to it. You can always, of course, with an objectID reconstituted from your
URI, do a fetch with a predicate like "self == %@", which will retrieve
objects (or no object) with that objectID.
You'll probably get better answers than this on this list, but maybe this will
get you moving.
John
Guillaume Rager said:
>Just a small question about NSManagedObjectID.
>
>I have to link 2 different objects, in 2 different stores (cross
>store relationship), i'm using (NSURL) URIRepresentation. When i save
>the context and quit my application, the URIRepresentations are
>stored correctly in the database.
>But when the database is reloaded, if the object represented by the
>URIRepresentation has been deleted (during another application
>session for example), there is a BIG problem because I do not have
>any solution to know if the represented object (the destination of
>the cross store relation ship) still exists or not ?
>
>i'm using managedObjectIDForURIRepresentation then objectWithID: but
>this method *ALWAYS* returns an object (with no underlying datas
>because the object has been deleted).
>Using objectRegisteredForID: is not better, because it returns nil IF
>THE OBJECT HAS NOT BEEN REGISTERED (fetched?), OR IF THE OBJECT DOES
>NOT EXIST. I can not afford a "fetch all" each time, then use
>objectForRegisteredID: and check if nil to be sure the represented
>object still exists...
>
>By the way, where is "registered" for a NSManagedObject defined, what
>does it means?
available - instantiated or fault - in the context
>Currently i'm forced to catch the "Core data could not fulfill a
>fault" exception to check if the underlying data exists... and
>nullify the relationship destination if necessary
>
>Scary monday... what about tomorrow :-)
Probably scary, too!
------------------------------------------------------------------
John Bishop <mailto:email@hidden>
Mulligan Software <http://www.mulligansoftware.com>
Mulligan's Golf Personal - Stats & Handicapping for the Mac Golfer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden