• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Core Data doesn't save toMany relations please HELP :S
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data doesn't save toMany relations please HELP :S


  • Subject: Core Data doesn't save toMany relations please HELP :S
  • From: Gustavo Pizano <email@hidden>
  • Date: Thu, 25 Mar 2010 16:36:54 +0100

Hello, all.

I came up with a problem where my entity Invoice has a toMany relation to an entity called, ItemXInvoice, which hold the quantity and the total price, so when I create an Invoice I add ItemXInvoice's when clciking an add button, these ItemXInvoice's are stored in a NSArrayController. then wen I click the save button for the invoice I do the following:

	if(_newInvoice == nil){ //If its equal  nil then I create a new MO
		_newInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"Invoice" inManagedObjectContext:[self managedObjectContext]];
		//Setting the Relationship Witht the User.
		[(User *)[[[parent _userListArrayController] selectedObjects] objectAtIndex:0] addToInvoicesObject:_newInvoice];
		//Settting the RelationShip To the Customer.
		[(Client *)[[_clientsArrayController selectedObjects] lastObject] addToInvoicesObject:_newInvoice];

	}
	//Set the creationItemPrice for each ItemXInvoice


	for(ItemXInvoice * acutalItem in [_itemsArrayController arrangedObjects]){
		[acutalItem setValue:[acutalItem valueForKeyPath:@"toItem.unitPrice"] forKey:@"creationItemPrice"];
		[acutalItem setValue:[self getNewStatusEntity] forKey:@"toStatus"];
	}

	[_newInvoice addToItemsXInvoice:[NSSet setWithArray:[_itemsArrayController arrangedObjects]]];
	...
	...
	so then I jsut save the managedObjectContext,  and  there is no error.

then when I want to check the invoice, I get the NSSet from the relation ship like this:

NSArrayController * ctr = [(InvoiceLayoutViewController *)object _invoicesArrayController];

	NSSet * temp = [(Invoice *)[[ctr selectedObjects] lastObject] valueForKey:@"toItemsXInvoice"];
	NSLog(@"Changed selection %i",[temp count]);

and the output I get is a 0, and sometimes, I see a 2 or 1, but normally its just 0, and of course I can't see the description of each invoice.

I tried then saving first the ItemXIvnoices from the NSArrayController, but still same effect I get an empty set from the  Invoice M.O,
what can I do? what am I doing wrong?

Thx

Gustavo


	_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Core Data doesn't save toMany relations please HELP :S
      • From: Gustavo Pizano <email@hidden>
    • Re: Core Data doesn't save toMany relations please HELP :S
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Please help, i'm newbe in cocoa + oracle programming.
  • Next by Date: NSXML Parsing Problem
  • Previous by thread: Re: Please help, i'm newbe in cocoa + oracle programming.
  • Next by thread: Re: Core Data doesn't save toMany relations please HELP :S
  • Index(es):
    • Date
    • Thread