• 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
Re: Core Data doesn't save toMany relations please HELP :S
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Core Data doesn't save toMany relations please HELP :S
  • From: Gustavo Pizano <email@hidden>
  • Date: Fri, 26 Mar 2010 14:16:53 +0100

Hello all again,

So was digging more into the problem, and realize that  the Items are being saved the ItemXInvoice are being saved and related to the invoice, but I can't acces the invoice detail (ItemXInvoice) immediately I get a console error:

Cannot remove an observer <NSTableBinder 0x116087000> for the key path "toItem.descr" from <ItemXInvoice 0x116024800>, most likely because the value for the key "toItem" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the ItemXInvoice class.

I then checked the class and in the setItem Im doing:

-(void)setToItem:(Item *)value{
	[self willChangeValueForKey:@"toItem"];
	[value retain];
	[self setPrimitiveValue:value forKey:@"toItem"];
	[self didChangeValueForKey:@"toItem"];
}

when I quit the application and reopened I can see the detial without problem, but when I create an Invoice and try to check it right after I can not.  These are the methods Im usign when creating ItemXDetail and saving the invoice Invoice:

-(IBAction)addItemXInvoice:(id)sender{

	Item  * newItem = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:[self managedObjectContext]];
	ItemXInvoice * newItemXInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"ItemXInvoice" inManagedObjectContext: [self managedObjectContext]];
	[newItemXInvoice willChangeValueForKey:@"toItem"];
	[newItemXInvoice setValue:newItem forKey:@"toItem"];
	[newItemXInvoice didChangeValueForKey:@"toItem"];
	[_itemsArrayController addObject:newItemXInvoice];
	if(_newInvoice == nil){
		_newInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"Invoice" inManagedObjectContext:[self managedObjectContext]];
	}
	[_newInvoice addToItemsXInvoiceObject:newItemXInvoice];
	[_tempItemsArray addObject:newItem]; //I need to keep track of the newly created itmes by this method so I can safelty remove them.
	//Set the creationItemPrice for each ItemXInvoice


}

the above creates a new Item, and a nte ItemXInvoice and relate them togheter then checks if _newinvoice instance is nil, if so then creates one, and relate the itemXInvoice to it.

-(IBAction)setPredefinedItem:(id)sender{
	ItemXInvoice * newItemXInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"ItemXInvoice" inManagedObjectContext: [self managedObjectContext]];
	NSMenuItem * menuItem = [_predefinedItems selectedItem];
	NSInteger indexOfItem = [_predefinedItems indexOfItem:menuItem];
	[newItemXInvoice setValue:[[_prefetchedItems arrangedObjects] objectAtIndex:indexOfItem]  forKey:@"toItem"];
	if(_newInvoice == nil){
		_newInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"Invoice" inManagedObjectContext:[self managedObjectContext]];
	}
	[_itemsArrayController addObject:newItemXInvoice];

}

Here I get a precreated Item, that I select form a poop up, then I create a ItemXInvoice and relate them together, and then I relate it to the _newInvoce instance.


Then when I click the save button":

if(_newInvoice != nil){
	[(User *)[[[parent _userListArrayController] selectedObjects] objectAtIndex:0] addToInvoicesObject:_newInvoice]; //Setting the Relationship Witht the User.
	[(Client *)[[_clientsArrayController selectedObjects] lastObject] addToInvoicesObject:_newInvoice];	//Settting the RelationShip To the Customer.

	for(ItemXInvoice * acutalItem in [_itemsArrayController arrangedObjects]){//Set the creationItemPrice for each ItemXInvoice
		[acutalItem setValue:[acutalItem valueForKeyPath:@"toItem.unitPrice"] forKey:@"creationItemPrice"];
		[acutalItem setValue:[self getNewStatusEntity] forKey:@"toStatus"];
	}
//I relate the selected user to the invoice (by this time the _newInvoice instnace shall not be null)
// then I iterate through all the elements in the ItemXInvoice Array Controller, and  set the unit Item Price and the toStatus,  the following lines set up the attributes of the invoice, and then I jsut save, call the method:

	if([managedObjectContext save:&error] == NO) {

and present an alert.

Now in the NSTable where Im putting the ItemXInvoice values,  the first column, is toItem.descr , (Item has attributes of descr and unitPrice). the second column is quantity which is attribute of ItemXInvoice, and the third one is unit price with bound to toItem.unitPrice,  So I dunno if its because of this way Im managing the table that its being boydn to a NSArrayController of ItemXInvoice, and when I push the add button, I do  what -(IBAction)addItemXInvoice:(id)sender{ shows, and then somehow the item its not being related whith the ItemxIvnoice or its not notifying of the change.

Im kinda lost already..


any help some where?

thanks

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

References: 
 >Core Data doesn't save toMany relations please HELP :S (From: Gustavo Pizano <email@hidden>)

  • Prev by Date: Re: Sync .DS_Store files
  • Next by Date: Re: Sync .DS_Store files
  • Previous by thread: Re: Core Data doesn't save toMany relations please HELP :S
  • Next by thread: Re: Core Data doesn't save toMany relations please HELP :S
  • Index(es):
    • Date
    • Thread