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

  • Home
  • SEARCH
  • 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 8212337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:43:21+00:00 2026-06-07T10:43:21+00:00

I have an entity (on Core Data ) called Contact , each contact has

  • 0

I have an entity (on Core Data) called Contact, each contact has a Neighborhood, User and ContactOrigin entities related with it.
When I retrive the JSON data from the server, I get something like this:

{
  "contact" : [
    {
      "prospect" : {
        "pkProspect" : 21,
        "name" : "Test Contact",
        "email" : "test@domain.com",
        "phone" : "5555555555",
        "address" : "Test Avenue",
        "media" : {
          "pkMedia" : 3,
          "name" : "Referência Entrevista You Move"
        },
        "neighborhood" : {
          "pkNeighborhood" : 15857,
          "name" : "Donwtown"
        }
      },
      "user" : {
        "firstName" : "John",
        "pkPerson" : 5,
        "lastName" : "Doe"
      }
    }
  ]
}

So as you can see, I have an array of contacts and each contact has a user node, a neighborhood node and a media node (which I use as origin on my database).
RestKit seems to be mapping this the right way with this code:

// Getting the object manager.
RKObjectManager *objectManager = [RKObjectManager sharedManager];

// Relationship mappings.    
RKManagedObjectMapping *neighborhoodMapping = [RKManagedObjectMapping mappingForClass:[Neighborhood class] inManagedObjectStore:objectManager.objectStore];
neighborhoodMapping.primaryKeyAttribute = @"identifier";
[neighborhoodMapping mapKeyPath:@"pkNeighborhood" toAttribute:@"identifier"];

RKManagedObjectMapping *originMapping = [RKManagedObjectMapping mappingForClass:[ContactOrigin class] inManagedObjectStore:objectManager.objectStore];
originMapping.primaryKeyAttribute = @"identifier";
[originMapping mapKeyPath:@"pkMedia" toAttribute:@"identifier"];

RKManagedObjectMapping *userMapping = [RKManagedObjectMapping mappingForClass:[User class] inManagedObjectStore:objectManager.objectStore];
userMapping.primaryKeyAttribute = @"identifier";
[userMapping mapKeyPath:@"pkPerson" toAttribute:@"identifier"];

// Creating the contact mapping for the request.
RKManagedObjectMapping *contactMapping = [RKManagedObjectMapping mappingForClass:[Contact class] inManagedObjectStore:objectManager.objectStore];
contactMapping.primaryKeyAttribute = kContactFieldNameId;

[contactMapping mapKeyPath:@"prospect.neighborhood" toRelationship:@"addressNeighborhood" withMapping:neighborhoodMapping];
[contactMapping mapKeyPath:@"prospect.media" toRelationship:@"origin" withMapping:originMapping];
[contactMapping mapKeyPath:@"user" toRelationship:@"user" withMapping:userMapping];

[contactMapping connectRelationship:@"addressNeighborhood" withObjectForPrimaryKeyAttribute:@"identifier"];
[contactMapping connectRelationship:@"origin" withObjectForPrimaryKeyAttribute:@"identifier"];
[contactMapping connectRelationship:@"user" withObjectForPrimaryKeyAttribute:@"identifier"];

[contactMapping mapKeyPath:@"prospect.pkProspect" toAttribute:@"identifier"];
[contactMapping mapKeyPath:@"prospect.name" toAttribute:@"name"];
[contactMapping mapKeyPath:@"prospect.email" toAttribute:@"email"];
[contactMapping mapKeyPath:@"prospect.phone" toAttribute:@"phone"];
[contactMapping mapKeyPath:@"prospect.address" toAttribute:@"address"];

// Setting the result mapping.
[objectManager.mappingProvider setObjectMapping:contactMapping forKeyPath:@"contact"];
// Loading data.
[objectManager loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader *loader) {
    loader.delegate = self;
    loader.userData = delegate;
}];

When the mapping is complete, I receive the following message (I’m showing just the User error):

2012-07-06 18:20:23.016 Contact Manager[8254:10c03] E restkit.core_data:RKManagedObjectStore.m:250 Core Data Save Error
                               NSLocalizedDescription:      The operation couldn’t be completed. (Cocoa error 1570.)
                               NSValidationErrorKey:            user
                               NSValidationErrorPredicate:  (null)
                               NSValidationErrorObject:
<Contact: 0x917dff0> (entity: Contact; id: 0x917e070 <x-coredata:///Contact/t9D9EE4AE-142A-45EC-88C1-E97833729D0C2> ; data: {
    address = "Test Avenue";
    addressNeighborhood = "0x918b5b0 <x-coredata://6E5AB6F3-AFF4-460E-A37D-285A105178F0/Neighborhood/p21>";
    email = "test@domain.com";
    identifier = 21;
    name = "Test Contact";
    origin = nil;
    phone = 5555555555;
    user = nil;
})
2012-07-06 18:20:23.024 Contact Manager[8254:10c03] E restkit.core_data:RKManagedObjectLoader.m:167 Failed to save managed object context after mapping completed: The operation couldn’t be completed. (Cocoa error 1560.)

As you can see, both origin and user are null and this is causing a error when I try to save it on Core Data because those fields are required, but if we take a look at the logs from RestKit we’ll see that those objects have been parsed correctly and in fact they exists in the database.

2012-07-06 18:20:22.938 Contact Manager[8254:10c03] D restkit.object_mapping:RKObjectMappingOperation.m:636 Starting mapping operation...
2012-07-06 18:20:22.940 Contact Manager[8254:10c03] T restkit.object_mapping:RKObjectMappingOperation.m:637 Performing mapping operation: RKObjectMappingOperation for 'User' object. Mapping values from object {
    firstName = John;
    lastName = Doe;
    pkPerson = 5;
} to object <User: 0x5ca9d60> (entity: User; id: 0xc5aa7a0 <x-coredata://6E5AB6F3-AFF4-460E-A37D-285A105178F0/User/p1> ; data: {
    contacts = "<relationship fault: 0xc5ab580 'contacts'>";
    email = "john@domain.com";
    identifier = 5;
    ip = "0.0.0.0";
    isLoggedIn = 1;
    language = "en";
    name = "John Doe";
    password = 4badaee57fed5610012a296273158f5f;
}) with object mapping <RKManagedObjectMapping:0x5ca78b0 objectClass=User keyPath mappings => (
    "RKObjectKeyPathMapping: pkPerson => identifier"
)>
2012-07-06 18:20:22.942 Contact Manager[8254:10c03] T restkit.object_mapping:RKObjectMappingOperation.m:330 Mapping attribute value keyPath 'pkPerson' to 'identifier'
2012-07-06 18:20:22.943 Contact Manager[8254:10c03] D restkit.object_mapping:RKObjectPropertyInspector.m:107 Cached property names and types for Class 'User': {
    accessibilityHint = NSString;
    accessibilityLabel = NSString;
    accessibilityLanguage = NSString;
    accessibilityValue = NSString;
    contacts = NSSet;
    email = NSString;
    identifier = NSNumber;
    ip = NSString;
    isLoggedIn = NSNumber;
    language = NSString;
    name = NSString;
    password = NSString;
}
2012-07-06 18:20:22.944 Contact Manager[8254:10c03] T restkit.object_mapping:RKObjectMappingOperation.m:347 Skipped mapping of attribute value from keyPath 'pkPerson to keyPath 'identifier' -- value is unchanged (5)
2012-07-06 18:20:22.946 Contact Manager[8254:10c03] D restkit.object_mapping:RKObjectMappingOperation.m:643 Finished mapping operation successfully...
2012-07-06 18:20:22.966 Contact Manager[8254:10c03] T restkit.object_mapping:RKObjectMappingOperation.m:597 Mapped relationship object from keyPath 'user' to 'user'. Value: <User: 0x5ca9d60> (entity: User; id: 0xc5aa7a0 <x-coredata://6E5AB6F3-AFF4-460E-A37D-285A105178F0/User/p1> ; data: {
    contacts = "<relationship fault: 0xc5ab580 'contacts'>";
    email = "john@domain.com";
    identifier = 5;
    ip = "0.0.0.0";
    isLoggedIn = 1;
    language = "pt_BR";
    name = "John Doe";
    password = 4badaee57fed5610012a296273158f5f;
})
2012-07-06 18:20:22.968 Contact Manager[8254:10c03] D restkit.object_mapping:RKObjectMappingOperation.m:643 Finished mapping operation successfully...

So, my question here is why user and origin are null if the parser found those objects into the database? Is there anything wrong with the mapping?

  • 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-06-07T10:43:22+00:00Added an answer on June 7, 2026 at 10:43 am

    After a lot of debugging I found a way to fix it. First, the fact that I was using the same primary key (@"identifier") for every object, was messing up with the mapping.

    After that, I’ve removed the [contactMapping connectRelationship:withObjectForPrimaryKeyAttribute:] because it’s not needed and now everything seems to be working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple core-data entity that has a Boolean attribute called subscribedToNewsletter .
I have a core data entity called images that has just 2 fields: imageName
I have an Core Data entity called Album; an album has a relationship to
I have an entity in core data that has 2 Attributes. One that is
In my core data model I have a Person entity that has a to
I have a document-based Core Data app. My main Core Data entity has several
I have 4 entities in my core data with the same parent entity. They
I have an entity called Task in my Core Data model. The Task entity
im using core data i have an entity called questions whenever i add my
I have a Core Data entity, bid, which has a relationship to many items,

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.