Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3978782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:05:23+00:00 2026-05-20T05:05:23+00:00

I’m dealing with an annoying problem in core data I’ve got a table named

  • 0

I’m dealing with an annoying problem in core data I’ve got a table named Character, which is made
as follows

Character table structure

I’m filling the table in various steps:
1) fill the attributes of the table
2) fill the Character Relation (charRel)

FYI charRel is defined as follows

charRel structure

I’m feeding the contents by pulling the data from an xml,
the feeding code is this

curStr = [[NSMutableString stringWithString:[curStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] retain];
NSLog(@"Parsing relation within these keys %@, in order to get'em associated",curStr);
NSArray *chunks = [curStr componentsSeparatedByString: @","];

for( NSString *relId in chunks ) {
    NSLog(@"Associating %@ with id %@",[currentCharacter valueForKey:@"character_id"], relId);
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"character_id == %@", relId];
    [request setEntity:[NSEntityDescription entityForName:@"Character" inManagedObjectContext:[self managedObjectContext] ]];
    [request setPredicate:predicate];

    NSerror *error = nil;
    NSArray *results = [[self managedObjectContext] executeFetchRequest:request error:&error];

    // error handling code
    if(error != nil)
    {
    NSLog(@"[SYMBOL CORRELATION]: retrieving correlated symbol error: %@", [error localizedDescription]);
    } else if([results count] > 0) {
    Character *relatedChar = [results objectAtIndex:0]; // grab the first result in the stack, could be done better!
    [currentCharacter addCharRelObject:relatedChar];

    //VICE VERSA RELATIONS
    NSArray *charRels = [relatedChar valueForKey:@"charRel"];
    BOOL alreadyRelated = NO;
    for(Character *charRel in charRels) {
        if([[charRel valueForKey:@"character_id"] isEqual:[currentCharacter valueForKey:@"character_id"]])    
        {
        alreadyRelated = YES;
        break;
        }
    }

    if(!alreadyRelated)
    {
        NSLog(@"\n\t\trelating %@ with %@", [relatedChar valueForKey:@"character_id"], [currentCharacter valueForKey:@"character_id"]);
        [relatedChar addCharRelObject:currentCharacter];
    }

    } else {
    NSLog(@"[SYMBOL CORRELATION]: related symbol was not found! ##SKIPPING-->");
    }
    [request release];
}

NSLog(@"\t\t### TOTAL OF REALTIONS FOR ID %@: %d\n%@", [currentCharacter valueForKey:@"character_id"], [[currentCharacter valueForKey:@"charRel"] count], currentCharacter);

error = nil;
/* SAVE THE CONTEXT */
if (![managedObjectContext save:&error]) {
    NSLog(@"Whoops, couldn't save the symbol record: %@", [error localizedDescription]);
    NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
    if(detailedErrors != nil && [detailedErrors count] > 0) {
    for(NSError* detailedError in detailedErrors) {
        NSLog(@"\n################\t\tDetailedError: %@\n################", [detailedError userInfo]);
    }
    }
    else {
    NSLog(@"  %@", [error userInfo]);
    }
}

at this point when I print out the values of the currentCharacter, everything looks perfect. every relation is in its place.
in example in this log we can clearly see that this element has got 3 items in charRel:

<Character: 0x5593af0> (entity: Character; id: 0x55938c0 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p86> ; data: {
    catRel = "<relationship fault: 0x9a29db0 'catRel'>";
    charRel =     (
        "0x9a1f870 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p74>",
        "0x9a14bd0 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p109>",
        "0x558ba00 <x-coredata://67288D50-D349-4B19-B7CB-F7AC4671AD61/Character/p5>"
    );
    "character_id" = 254;
    examplesRel = "<relationship fault: 0x9a29df0 'examplesRel'>";
    meaning = "\n  Left";
    pinyin = "\n  zu\U01d2";
    "pronunciation_it" = "\n  zu\U01d2";
    strokenumber = 5;
    text = "\n  \n    <p>The most ancient form of this symbol";
    unicodevalue = "\n  \U5de6";
})

then when I’m in need of retrieving this item I perform an extraction, like this:

// at first I get the single Character record
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSError *error;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"character_id == %@", self.char_id ];
[request setEntity:[NSEntityDescription entityForName:@"Character" inManagedObjectContext:_context ]];
[request setPredicate:predicate];
NSArray *fetchedObjs = [_context executeFetchRequest:request error:&error];

when, for instance, I print out in NSLog the contents of charRel

NSArray *correlations = [singleCharacter valueForKey:@"charRel"];
NSLog(@"CHARACTER OBJECT \n%@", correlations);

I get this

Relationship fault for (<NSRelationshipDescription: 0x5568520>), name charRel, isOptional 1, 
isTransient 0, entity Character, renamingIdentifier charRel, validation predicates (), warnings (), 
versionHashModifier (null), destination entity Character, inverseRelationship (null), minCount 1, 
maxCount 99 on 0x6937f00

hope that I made myself clear.
this thing is driving me insane, I’ve googled all over world, but
I couldn’t find a solution (and this make me think to as issue related to bad coding somehow :P).

thank you in advance guys.
k

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:05:24+00:00Added an answer on May 20, 2026 at 5:05 am

    ok I solved this issue,
    the problem was related to some facts:

    1) the relation has to be inverse, otherwise the system for some (unknown) reasons messes up everything. [like the figure below]

    enter image description here

    2) In order to have this model work properly, saving stuff in the real way, I added

    [managedObjectContext refreshObject:relatedChar mergeChanges:YES];
    

    and

    [managedObjectContext processPendingChanges];
    [managedObjectContext refreshObject:currentCharacter mergeChanges:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.