RestKit Object Mapping relationships with foreign keys

后端 未结 1 1343
北海茫月
北海茫月 2021-02-05 20:08

Can RestKit connect a relationship without storing the foreign key as an attribute, i.e., directly from the keypath in the JSON?

In particular, I\'ve got a Job has_many

相关标签:
1条回答
  • 2021-02-05 20:46

    I would make JobId a transient value in core data, and write a custom set and get for it.

    The set would set the relationship to self.job=methodToReturnObjectMatchingJobId (this would be used by rest kit)

    The get would return self.job.identifier

    If you are not using mogenerator, I would suggest you have a look at it for all your core data needs.

    Below is sample code of how i did it:

    -(void) setClaimId:(NSNumber *)claimId{
         Claim *propertyClaim=[Claim listItemFromId:[claimId intValue] withContext:self.managedObjectContext]; 
    
        self.claim=propertyClaim; 
    }
    -(NSNumber*) claimId{
    
      return self.claim.referenceId;
    }
    

    where listItemFromId is a simple query that returns the object based on the id.

    0 讨论(0)
提交回复
热议问题