New ManagedObject with relationship problem

  • 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
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today