0

私は、MedicationCase エンティティの複数のインスタンスを持つことができる CaseHistory と呼ばれる親エンティティを持っています。

次のようなコード:

@interface CaseHistory : NSManagedObject
@property (nonatomic, retain) NSSet *medicationCaseSet;
@end

@interface MedicationCase : NSManagedObject

@property (retain, nonatomic)CaseHistory *caseHistory;
@end

次に、MedicationCase インスタンスを新規作成し、コンテキストに挿入して保存します。

_tempMedicationCase =  [[BusinessManager sharedInstance].caseHistoryManager newMedicationCase];
 [[BusinessManager sharedInstance].caseHistoryManager insertnewMedicationCase:_tempMedicationCase];

 if(! [_tempCaseHistory.medicationCaseSet containsObject:_tempMedicationCase])
  {
     [_tempCaseHistory addMedicationCaseSetObject:_tempMedicationCase];
  }
[[BusinessManager sharedInstance] save];

次に、結果をフェッチします。問題ありませんが、アプリを終了してから古い結果をフェッチすると、NULL になります。

(lldb) po caseHistoryArray
<__NSArrayM 0x20002a80>(
<CaseHistory: 0x200017e0> (entity: CaseHistory; id: 0x20002380 <x-coredata://ADB63B4E-7622-4101-9546-CFA53ACD28E9/CaseHistory/p1> ; data: {
    medicationCaseSet =     (
    );
})
)

コンテンツファイルは次のとおりです。

 <model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="2061" systemVersion="12E55" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
    <entity name="CaseHistory" syncable="YES">
        <relationship name="medicationCaseSet" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MedicationCase" inverseName="caseHistory" inverseEntity="MedicationCase" syncable="YES"/>
    </entity>
    <entity name="MedicationCase" syncable="YES">
        <relationship name="caseHistory" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="CaseHistory" inverseName="medicationCaseSet" inverseEntity="CaseHistory" syncable="YES"/>
    </entity>
</model>
4

0 に答える 0