Re: Predicates with object identity values
Re: Predicates with object identity values
- Subject: Re: Predicates with object identity values
- From: Glen Low <email@hidden>
- Date: Wed, 30 May 2007 14:07:21 +0800
Chris, All
On 25/05/2007, at 3:39 PM, Chris Hanson wrote:
A Department object has many Employee objects. There is a relation
Department -> Employee (employee) but no inverse relation Employee
-> Department.
Generally speaking, all relationships should have an inverse.
Otherwise Core Data has to guess as to the intent of the
relationship in some situations, and it may guess differently than
you would.
What is it you hope to gain by not having an inverse relationship?
I'll be partitioning the data into two persistent stores. Store A
will contain metadata or structural data that doesn't change on
typical use, and will be opened as read-only with configuration A.
Store B will contain actual data that is edited often, and will be
opened as R/W with configuration B. Also there may be many such B
stores, but only one A store; however at one one time only one of B
and A will be opened at a time.
Therefore objects in the B store reference objects in the A store but
not vice versa.
Is this a correct, supported configuration for CoreData?
Suppose I have an Employee object called myEmployee and want to
search for its Department, can I use the following fetch request?
NSFetchRequest* request = [[NSFetchRequest alloc] init];
[request setEntity: departmentEntity];
[request setPredicate: [NSPredicate predicateWithFormat:
@"employee = %@", myEmployee]]; // using myEmployee as an object
identity
This is exactly how you'd do it. You could also have passed
myEmployee's managed object ID instead; which can be useful in some
situations (e.g. multithreading).
I'd suppose you would do a
[NSPredicate predicateWithFormat: @"employee.objectId = %@",
[myEmployee objectId]]
instead?
Doesn't the objectId change after the object's first save?
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
aim: pixglen
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden