RE: Fetch request problem with core data relationship and NSTableView
RE: Fetch request problem with core data relationship and NSTableView
- Subject: RE: Fetch request problem with core data relationship and NSTableView
- From: "Danny Callanan" <email@hidden>
- Date: Fri, 15 Jun 2007 17:08:10 +0100
- Organization: Oracle
I appreciate your time and help with this but, after taking your suggestion and building a small sample app, I still have the problem. I could send you the project but, even in zipped form, it's 1.7mb so I'm guessing you wouldn't thank me for it. The steps I took were really simple though. Could I describe them?
I created a model with two entities: Charge and Currency each with a string attribute called 'name'. The Charge entity has a to-many relationship to Currency (called 'toCurrency') and the Currency entity has a reciprocal relationship to Charge called 'toCharge'.
I created the interface in IB simply by option-dragging entities from my diagram into IB (taking the 'many objects' option to create table views for each entity). That's all I did in IB.
I created custom classes for Charge and Currency using the File/New ... option. I then modified the awakeFromInsert method for the Charge class to look like
- (void) awakeFromInsert
{
NSManagedObjectContext *moc = [self managedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Currency" inManagedObkectContext:moc];
[request setEntity:entity];
NSError *error = nil;
NSArray *tempArray = [moc executeFetchRequest:request error:&error];
[self setToCurrency:[tempArray lastObject]];
}
The 'setToCurrency:' method mentioned above was auto-created by the wizard for me within Charge.
Running the new sample app produces the same behaviour as before.
Interestingly, following your suggestion regarding re-fetching the arrayController, this immediately corrects the table display (i.e. changes it from showing two rows to just one)!
I knew I should have gone to WWDC instead ...!
Thanks for any and all help with this.
Danny
-----Original Message-----
From: I. Savant [mailto:email@hidden]
Sent: 15 June 2007 16:06
To: email@hidden
Cc: email@hidden
Subject: Re: Fetch request problem with core data relationship and
NSTableView
> I have an array controller bound to the managedObjectContext. Each NSTableColumn of the NSTableView from the interface is bound to the underlying model via the controller. I have an 'add' button that is similarly bound to the controller.
So you're not creating/inserting in code, you're relying on the
array controller ...
> | 4 - What happens if you force your array controller to -fetch:
> |after you create your Charge instance?
>
> What would be the best approach to doing this?
... by wiring your "add" button to a custom action method, then
sending -add: then -fetch: to the array controller.
BUT, since you're relying on the array controller's -add: method
directly this should not be producing the results you described, so
even if sending a manual -fetch: resolves this problem, the cause
remains a mystery and so does any possible hidden side-effects. I say
this because I've never seen this behavior before and it seems wrong.
Very very wrong.
I suggest reproducing a small test case outside your own project and
see if you get the same results. I'm betting you won't. If you do,
post that test case somewhere for the list to take a look. If you
*don't* get the same results with a small test case, then you can
compare/contrast with your actual project and see what you're doing
differently.
--
I.S.
_______________________________________________
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