Core-Data, can you issue an NSrequest from awakefrominsert
Core-Data, can you issue an NSrequest from awakefrominsert
- Subject: Core-Data, can you issue an NSrequest from awakefrominsert
- From: Richard Dearlove <email@hidden>
- Date: Mon, 24 Apr 2006 18:43:59 +0100
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:
This email sent to email@hidden