user5730430
user5730430

Reputation:

How to Rectify the Relationship Fault in CoreData While parsing RESTKIT?

I want to Store the EY_ConnectionUsage Entity value to the EY_Connection entity Cell.I have Added two Entities with Attributes and Created Relationship with name usageData.But this Shows error "<'usageData' Relationship Fault>".This is a Method I wrote to map the RESTKIT value to CoreData.

DataAccessHandler.m

+(void)createConnectionMappingWithStore:(RKManagedObjectStore *)managedObjectStore saveInDelegate:(AppDelegate *)appDelegate{

NSLog(@"appdele==>>%@",appDelegate);
RKEntityMapping *connectionMapping = [RKEntityMapping mappingForEntityForName:@"EY_Connections" inManagedObjectStore:managedObjectStore];
connectionMapping.identificationAttributes = @[@"connectionNumber"];
[connectionMapping addAttributeMappingsFromDictionary:@{ @"ServiceNo" : @"connectionServiceNumber", @"Name" : @"connectionName", @"Region" : @"connectionRegion", @"Phase" : @"connectionPhase",
    @"Circle" : @"connectionCircle", @"Section" : @"connectionSection", @"Load" : @"connectionLoad",
    @"Distribution" : @"connectionDistribution", @"MeterNo" : @"connectionMeterNumber", @"ConnectionNumber" : @"connectionNumber", @"Address" : @"connectionAddress", @"ServiceStatus" : @"connectionStatus"}];



RKEntityMapping *connectionUsageMapping = [RKEntityMapping mappingForEntityForName:@"EY_ConnectionUsage" inManagedObjectStore:managedObjectStore];
connectionUsageMapping.identificationAttributes = @[@"usageAssessmentDate"];
[connectionUsageMapping addAttributeMappingsFromDictionary:@{ @"assessment_date" : @"usageAssessmentDate", @"reading" : @"usageReading", @"units" : @"usageUnits", @"amount" : @"usageAmount",
                                                         @"payment_date" : @"usagePaymentDate", @"status" : @"usageStatus"}];

[connectionMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"usage" toKeyPath:@"usageData" withMapping:connectionUsageMapping]];

RKResponseDescriptor *articleListResponseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:connectionMapping
                                             method:RKRequestMethodGET
                                        pathPattern:@"user_history/consumer/data.json"
                                            keyPath:nil
                                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)
 ];

[appDelegate createObjectManagerForurl:@"http://sciflare.com/energyly/api/" andAddResponseDescriptor:articleListResponseDescriptor];
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;

}

Upvotes: 0

Views: 93

Answers (2)

Gagan_iOS
Gagan_iOS

Reputation: 4060

CoreData says that 'load only needed data'. If we are trying to fetch unwanted data then coredata shows 'FAULT'.

Foe more detail please go through CoreData Fault

Upvotes: 0

Wain
Wain

Reputation: 119031

<'usageData' Relationship Fault>

This means that the relationship data hasn't been loaded yet, because you haven't tried to use it. Logging the object isn't enough to load the data. The whole point of the faulting system is to prevent too much data being loaded into memory at the same time.

So, basically, it isn't a problem that it's a fault. When you try to use it the data will be populated and everything will be fine.

Upvotes: 1

Related Questions