MMM I think I may know whats wrong.. the managedObjectContext contains only the newly insterted invoice but nothing about the user which comes from the NSArrayController.
So this makes me think that the ArrayController fetches the Entities but don't place them into the managedObjectContext?,... even when you define it in IB via bindings? G. On Nov 24, 2009, at 8:42 PM, Gustavo Pizano wrote: > Hello all. > > Here is what I have: an NSArryaController for my Entity User. and an > NSArrayController for my Entity Invoice. so this is what Im doing when saving > an invoice for a selected user. > > -(void)saveInvoiceForSender:(id)sender withParent:(UserListViewController > *)parent{ > > NSLog(@"Saving the invoice"); > (1) Invoice * newInvoice = [NSEntityDescription > insertNewObjectForEntityForName:@"Invoice" > inManagedObjectContext:managedObjectContext] > (2) [newInvoice setValue:[NSSet setWithArray:[_itemsArrayController > arrangedObjects]] forKey:@"toItems"]; > (3) [newInvoice setValue:_dueDateSelection forKey:@"dueDate"]; > (4) Address * invoiceAddress = [(Client *)[_clientsArrayController > selection] valueForKey:@"toAdress"]; > (5) //Setting up the addres into the invoice.. this way the addres info its > related to the invoice from now ON! > (6) [newInvoice setValue:[invoiceAddress valueForKey:@"street"] > forKey:@"billingStreet"]; > (7) [newInvoice setValue:[invoiceAddress valueForKey:@"country"] > forKey:@"billingCountry"]; > (8) [newInvoice setValue:[invoiceAddress valueForKey:@"city"] > forKey:@"billingCity"]; > (9) [newInvoice setValue:[invoiceAddress valueForKey:@"postalCode"] > forKey:@"billingPostalCode"]; > //Generating the next invoice Code > (10) if (!hasFetched) { > numberOfInvoices = [[(User *)[[parent _userListArrayController] > selection] valueForKey:@"toInvoices"] count]+1000; > hasFetched = YES; > } > (11) _nextInvoiceNumber = [NSString > stringWithFormat:@"SK-%i",numberOfInvoices]; > (12) [newInvoice setValue:_nextInvoiceNumber forKey:@"invoiceNumber"]; > (13) [newInvoice setValue:[NSDecimalNumber numberWithDouble:[_total > doubleValue]] forKey:@"totalInvoice"]; > //Setting the Relationship Witht the User. > > (14) NSLog(@"%@",[(User *)[[parent _userListArrayController] selection] > valueForKey:@"ico"]); > (15) [(User *)[[parent _userListArrayController] selection] > addToInvoicesObject:newInvoice]; > > /*NSError * error; > if([managedObjectContext save:&error] == NO) NSLog(@"Could not save the > new Client %@",[error localizedDescription]); > else { > NSLog(@"Save Succesfull"); > }*/ > Ok, so in (1), I created the Invoice Entity in the managedObjectContext that > I have form the awakefromnib form the sharedApplication... from 2-10 Im just > adding values to the properties. 10 Im generating the new Code... (I know > this can be done somehow else, but so far im concerning in be able to save > the data), 11-13 setting the invoice number, > > Now the interesting part, 14, I did jsut a test to see what I could get, and > eventually the way it is, I get the value of @"ico", BUT, If I try to do the > follwoing: NSLog(@"%@",[(User *)[[parent _userListArrayController] > selection] ico]);, then I get: > > -[_NSControllerObjectProxy ico]: unrecognized selector sent to instance > 0x100266580 > so in 15 when I try to add this newInvoice to the existing ones, with the > addToInvoicesObject method, I get also something like this : > > -[_NSControllerObjectProxy addToInvoicesObject:]: unrecognized selector sent > to instance 0x1001b7a10 > > so at the end I can't add an invoice to the selected user from the > _userListArrayController.. > > any clue what Im doing wrong? > > Thanks for the help > > Gustavo > PS the _userListArrayController has the managedObjectContext to be the same > form the sharedApplication . > > > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com