Next in what promises to be an unending series of questions about Core Data. This one has to do with following relationships and queries.
Here's a simple data model:
There are two managed objects, Owner and Thing. Owner owns many things, but a thing is only owned by one owner. I want to test to see if a given thing exists, and if it does exist, if it's owned by a given owner (theOwner). If it doesn't exist, I'm going to create it and link it to theOwner (newThing.owner = theOwner).
I know how to test if a given thing exists (with the assumption that the thing's name property is unique), but I don't know how to craft a fetch request such that it only looks for the ones that have owner = theOwner. Any pointers to how to create that fetch request?
Is it as simple as looking in the theThing.things set to see if the Thing I'm looking for is there? If I only fetch theOwner, does it populate the set appropriately? Is this where the magic of "faulting" comes into play?
Thanks!
Ron
Here's a simple data model:
There are two managed objects, Owner and Thing. Owner owns many things, but a thing is only owned by one owner. I want to test to see if a given thing exists, and if it does exist, if it's owned by a given owner (theOwner). If it doesn't exist, I'm going to create it and link it to theOwner (newThing.owner = theOwner).
I know how to test if a given thing exists (with the assumption that the thing's name property is unique), but I don't know how to craft a fetch request such that it only looks for the ones that have owner = theOwner. Any pointers to how to create that fetch request?
Is it as simple as looking in the theThing.things set to see if the Thing I'm looking for is there? If I only fetch theOwner, does it populate the set appropriately? Is this where the magic of "faulting" comes into play?
Thanks!
Ron
Last edited: