2014-04-15 20 views
2

我試圖將關係映射添加到我的請求映射之一。添加與關係名稱不同的關鍵路徑的Restkit關係映射

POST請求應發送主體內容,例如:

{ 「賬戶」:{ 「關鍵」: 「the_key_goes_here」, 「TERMS_OF_SERVICE」:1, 「person_attributes」:{ 「電子郵件」:」 [email protected]「}}}

我已經設置了帳戶映射是:現在

NSMutableDictionary *accountAttributes = [NSMutableDictionary dictionaryWithDictionary: @{@"key":@"key",@"terms_of_service":@"terms_of_service",@"source":@"source"}]; 
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; 
[requestMapping addAttributeMappingsFromDictionary:accountAttributes]; 

,企圖將person_attributes添加到請求,我做了以下內容:

NSMutableDictionary *userAttributes = [NSMutableDictionary dictionaryWithDictionary: @{@"first_name":@"first_name",@"last_name":@"last_name",@"email":@"email"}]; 
RKObjectMapping *userMapping = [RKObjectMapping requestMapping]; 
[userMapping addAttributeMappingsFromDictionary:userAttributes]; 
[requestMapping addRelationshipMappingWithSourceKeyPath:@"person" mapping:userMapping]; 

然而,這總是發送如:

{ 「賬戶」:{ 「關鍵」: 「the_key_goes_here」, 「TERMS_OF_SERVICE」:1, 「人」:{ 「電子郵件」:」 [email protected]「}}}

在試圖改變person_attributes我修改relationshipmappingwithsourcekeypath到:

[requestMapping addRelationshipMappingWithSourceKeyPath:@"person_attributes" mapping:userMapping]; 

但是,它失敗的錯誤,每次,他說:the entity Account is not key value coding-compliant for the key "person_attributes"

我理解,這是因爲Account沒有一個person_attributes值。有沒有辦法將keypath添加爲person,但將它發送爲person_attributes

感謝您的幫助提前!

回答

4

您需要使用RKRelationshipMapping類和relationshipMappingFromKeyPath:toKeyPath:withMapping:方法創建關係,然後使用addPropertyMapping:進行設置。

+0

太棒了!它終於奏效了。謝謝 –