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 13:41:38 +0100
- Organization: Oracle
Many thanks for your help.
> NSArray *tempArray = [moc executeFetchRequest:request error:&error];
> [self setToCurrency:[self [tempArray lastObject]]];
>
> This is very crudely bringing back the last Currency object (I'll
> want to refine this).
>
| First, no it's not. Since the order of fetched objects is not
|guaranteed by Core Data, you're getting "some Currency instance" but
|not necessarily the last one added. A "sortOrder" or "createdOrder"
|key would be needed (and sorted upon) to guarantee order.
OK. Point taken. I will introduce some logic here to ensure I get the right value.
> All appears to work except that the UI shows two new rows rather
> than one when the user adds a Charge object. This appears to be a
> problem with UI only however since if I quit the application and re-
> open it only a single row appears.
| 1 - How are you creating the Charge instance?
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.
| 2 - Do you mean specifically there are two Charge instances in a table that lists Charges?
When hitting the 'add' button two new rows are added to the NSTableView. Despite this only a single Charge object is actually being created. I confirmed this by quitting the application and then firing it up again: only a single new Charge is shown.
| 3 - Are the two objects really different objects or are they the
|same object listed twice? (there are a number of ways to test this -
|I leave that up to you)
There is a single object here only.
| 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?
Many thanks for all your help with this.
Danny
_______________________________________________
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