Re: Core-Data, can you issue an NSrequest from awakefrominsert
Re: Core-Data, can you issue an NSrequest from awakefrominsert
- Subject: Re: Core-Data, can you issue an NSrequest from awakefrominsert
- From: Wain <email@hidden>
- Date: Mon, 24 Apr 2006 20:00:54 +0100
Hi,
Browse through http://www.cocoabuilder.com/archive/message/cocoa/
2005/9/5/145761 for an explanation and solution.
Wain
On 24 Apr 2006, at 18:43, Richard Dearlove wrote:
In a test app, I incremented a textfield by looking up a value from
an entity which stored in the key form "name" & "value", which i
then incremented
I just moved to my proper app, and tried to add the code into the
awakeFromInsert method for the ManagedObject,
The problem is that calling the executeFetchRequest method causes
my bound NSTableView to show 2 new records for every 1 inserted.
What am I doing wrong. ??
I saw someone else doing something similar on Cocoadev but thought
i'd avoided the same problem
regards
R Dearlove
@implementation receipt
- (void)awakeFromInsert
{
[super awakeFromInsert]; // Call superclass first
// Ask the managed object context what the value should be - look
it up the entity for the Values:receipt_#:
NSManagedObjectContext *moc = [self managedObjectContext];
id request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *counter = [NSEntityDescription
entityForName: @"values" inManagedObjectContext: moc];
NSPredicate *searchPredicate = [ NSPredicate
predicateWithFormat:@"name=%@",@"ID" ];
NSSortDescriptor *sortDesc = [[ NSSortDescriptor alloc ]
initWithKey:@"name" ascending:YES ];// autorelease ];
[ request setEntity:counter]; // Set Request using
counters
[ request setPredicate:searchPredicate]; // Set Predicate
for search
[ request setSortDescriptors:[NSArray
arrayWithObject:sortDesc ] ]; // Set Sort Order for searc
id error = nil;
NSArray *arrayResults = [ moc executeFetchRequest:request error:
&error]; // <-------- THIS LINE, CAUSES DUPLICATES TO APPEAR
// more code...........
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40tekuris.com
This email sent to email@hidden
_______________________________________________
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