Isn't this
   [newObject addObject:newObject
toBothSidesOfRelationshipWithKey:@"addresses"];
wrong??

Shouldn't it be
    [newObject addObject:theAddress
toBothSidesOfRelationshipWithKey:@"addresses"];

Also,
 theAddress = [[Address alloc] init];
 probably should be  theAddress = [[[Address alloc] init] autorelease]

-dave



Cengiz Kayay wrote:

> Hi all again;
>
> Thanks for all the advices.
> Inserting new records are fine. What when it comes to update I have the
> following problem. I also saw the same complaint in the mailing lists
> and there was not any solution yet. Any help is greatly appreaciated. I
> already lost 2 days on this.
>
>  theAddress = [[Address alloc] init];
>
>     [theAddress setState:@"MD"];
>     [theAddress setCountry:@"USA"];
>
>     qual = [[EOKeyValueQualifier alloc] initWithKey:@"lastName"
> operatorSelector:EOQualifierOperatorEqual value:@"Quick"];
>    fetch = [EOFetchSpecification
> fetchSpecificationWithEntityName:@"Contact" qualifier:qual
> sortOrderings:nil];
>
>     theEditingContext = [[EOEditingContext alloc] init];
>     results= [theEditingContext objectsWithFetchSpecification:fetch];
>
>     newObject = [results objectAtIndex:0];
>
> // UPDATE A VALUE HERE
>     [newObject setFirstName:@"MY NAME"];
>
>
>    [theEditingContext insertObject:theAddress];
>
>     [newObject addObject:newObject
> toBothSidesOfRelationshipWithKey:@"addresses"];
>
>    [theEditingContext saveChanges];
>
> This will blow up with the following exception:
>
> Error: NSInternalInconsistencyException exception
> Reason:
> recordInsertForObject:: EODatabaseContext 0x458100 found a snapshot for
> EO with Global ID:[GID: Contact, (15773)] that has been inserted into
> EOEditingContext 0x5219150. Cannot insert an object that is already in
> the database.
>
> This means you can not update the main object which has many to many
> relations to others.
>
> If I do the [editingCOntext forgetObject:[newObject ]
>
> This will run but not for update...
>
> Thnaks for any quick reply..
>
> MC.
>
> >The weird thing here is that I had all that.
> >The code is below.
> >
> >    Address *theAddress;
> >    ContactAddress *newObject;
> >       EOEditingContext *theEditingContext;
> >
> >    theAddress = [[Address alloc] init];
> >    [theAddress setSecondAddress:@"vgbdfgd"];
> >    [theAddress setDelivAddress:@"gfgfjfdg"];
> >    [theAddress setCity:@"hgafdgdgsh"];
> >    [theAddress setZipPlus4:@"32332"];
> >    [theAddress setAddressForeignInd:@"Y"];
> >    [theAddress setAddressType:@"Main Business Address"];
> >    [theAddress setState:@"MD"];
> >    [theAddress setCountry:@"USA"];
> >   newObject = [[ContactAddress alloc] init];
> >
> >    [theAddress addObject:newObject
> >toPropertyWithKey:@"toContactAddress"];
> >    theEditingContext = [[self session] defaultEditingContext];
> >
> >    [theEditingContext insertObject:theAddress];
> >    [theEditingContext insertObject:newObject];
> >    [theEditingContext saveChanges];
> >
> >
> >Moreover in  my eomodel The Address table has a relation to the other
> >table and Owns object and propogate primary keys are selected.
> >
> >Guess what, when It inserts the object , both primary keys in the
> >destination table have been inserted as 0's.
> >
> >Any idea?
> >
> >thnaks a lot.
> >
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to