New ManagedObject with relationship problem
New ManagedObject with relationship problem
- Subject: New ManagedObject with relationship problem
- From: Baron Stephane <email@hidden>
- Date: Wed, 25 Oct 2006 22:20:16 +0200
I try to add an new entity by code
this entity have one reverse relationship, one to many
i have an entity item and an entity client
one item can have one client
a client can have many item
when i create the entity the log are fine for me
(i have no relationship fault message)
here is the nslog for the new entity:
2006-10-25 22:06:17.361 itemCD[1018:117] <NSManagedObject: 0x3edb30>
(entity: item; id: 0x3e7c20 <x-coredata:///item/t111736DC-4BD4-43BE-9E23-A5F561AC53282
> ; data: {
client = 0x304c90 <x-coredata://95879A34-20D6-4516-AE57-A255C666849C/Client/p106
>;
nameOfItem = "New Item";
prestations = ();
tva = 19.6;
})
the client selected is correctly set in the new entity
when i try to add the new entity to coredata i got this message:
2006-10-25 22:06:17.363 itemCD[1018:117] Cannot create NSSet from
object <Client: 0x3dd890> (entity: Client; id: 0x304c90 <x-coredata://95879A34-20D6-4516-AE57-A255C666849C/Client/p106
> ; data: {
adresse1 = "";
adresse2 = "";
codePostal = "";
isSociete = 0;
items = (0x3e7c20 <x-coredata:///item/t111736DC-4BD4-43BE-9E23-A5F561AC53282
>);
nom = ertert;
nomPrenom = "ertert ";
prenom = "";
societe = "";
ville = "";
}) of class Client
I don't understand what i am doing wrong, i have tryed to use
mutableSetValueForKey without succes or creating an NSSet and using
setValue:myNSSet before the addObject method without success
here is my code:
can someone tell where i am wrong ??
Thanks
NSManagedObject *newItem = [NSEntityDescription
insertNewObjectForEntityForName:@"item" inManagedObjectContext: [self
managedObjectContext]];
[newItem setValue:[fieldName stringValue] forKey:@"nameOfItem"];
[newItem setValue:[[arrayOfClients selectedObjects] objectAtIndex:0]
forKey:@"client"]; <--- the relationship
NSString *valueTVA=[[popUpTVA selectedItem]title];
NSDecimalNumber *myTVA=[NSDecimalNumber
decimalNumberWithString:valueTVA];
[newItem setValue:myTVA forKey:@"tva"];
[arrayOfItems addObject:newItem];
arrayOfItems and arrayOfClients are NSArrayController
_______________________________________________
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