RestKitのObject Mapping-Guide on GitHubを読んだ後、私の問題は消えませんでした。だから、RestKitが次のアイデアに対処できるかどうか誰かが言うことができます。関係RestKitオブジェクトマッピング関係KVCなし
Company
- unitID
- companyID
- name
- contacts* (Company -->> Contact | 1:n)
Contact
- unitID
- companyID
- contactID
- lastName
- firstName
- account* (Contact >--> Company | 1:1)
JSON(会社)との
エンティティ
[
{
"unitID":"003CABD8DEB5DC13C",
"companyID":"BSP-002999",
"name":"Testcompany"
}
]
JSON(連絡先)
[
{
"unitID":"DAC2ACCC125795D00",
"companyID":"BSP-002999",
"contactID":"CLP-015468",
"firstName":"Mister",
"lastName":"Wayne"
}
]
制限のため、所属する連絡先を会社にネストすることができません(そうでなければ私はこれを書いていません)ので、インポート時にデータがマッピングされたときにこの使い方をしたいと思います。
質問
は、各連絡先をマッピングすることが可能ですRestKitによって所定の方法でインポート時に(属性たCompanyIdで識別される)会社に属するのか?
もしそうでなければ、私はそれに最適な解決法を知りたいと思います。ありがとう!このアプリの私の最初のビルドで
背景
私は(関係なし)指定されたエンティティにオブジェクトをマッピングされ、述語企業IDを持つ企業へのすべての属する連絡先をフェッチしました=%@。データ量(4000以上の企業、7000以上の連絡先)のために、所属する連絡先をすべて取得するのに約1秒かかるので、リレーションシップを使用するというアイデアを思いつきました(ローカルダミーデータと完璧に機能します)。
ソリューション
私の現在のマッピング下記の答えの助けを借りて、以下の(RestKitのV.10)のように見えます。
// Setting up Restkit with objectStore
...
// Init objectMapping for Class Company
companyMapping = [RKManagedObjectMapping mappingForClass:[Company class] inManagedObjectStore:objectStore];
[companyMapping mapKeyPath:@"unitID" toAttribute:@"unitID"];
[companyMapping mapKeyPath:@"companyID" toAttribute:@"companyID"];
[companyMapping mapKeyPath:@"name" toAttribute:@"name"];
companyMapping.setDefaultValueForMissingAttributes = NO;
companyMapping.primaryKeyAttribute = @"companyID";
// Init objectMapping for Class Contact
contactMapping = [RKManagedObjectMapping mappingForClass:[Contact class] inManagedObjectStore:objectStore];
[contactMapping mapKeyPath:@"unitID" toAttribute:@"unitID"];
[contactMapping mapKeyPath:@"companyID" toAttribute:@"companyID"];
[contactMapping mapKeyPath:@"contactID" toAttribute:@"contactID"];
[contactMapping mapKeyPath:@"lastName" toAttribute:@"lastName"];
[contactMapping mapKeyPath:@"firstName" toAttribute:@"firstName"];
contactMapping.setDefaultValueForMissingAttributes = NO;
contactMapping.primaryKeyAttribute = @"contactID";
// Init relationships
[contactMapping mapRelationship:@"company" withMapping:companyMapping];
[contactMapping connectRelationship:@"company" withObjectForPrimaryKeyAttribute:@"companyID"];
// Get objects from server
...
あなたは、この例の作業ソリューションを共有していただけますか? :)マッピングのためだけに –
上記の私のエントリを設定例で更新しました。それが役に立てば幸い! – flashfabrixx