使用Core Data将两个实体合并为一个

时间:2011-12-16 23:34:44

标签: iphone objective-c cocoa-touch core-data nsfetchedresultscontroller

这是我的核心数据库的数据模型。

我现在需要获取所有ICD9对象,包括疾病和程序对象。我无法设置搜索来搜索两个实体,所以有没有办法将这些实体合并到一个ICD9对象而不是两个独立的对象中?

enter image description here

更新型号:

enter image description here

错误讯息:

Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x12ed7300 {metadata=<CFBasicHash 0x12ed5d20 [0x2f6eb38]>{type = immutable dict, count = 7,
entries =>
    2 : <CFString 0x12ed45b0 [0x2f6eb38]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x12ed4d80 [0x2f6eb38]>{type = immutable, count = 1, values = (
    0 : <CFString 0x2f69cd8 [0x2f6eb38]>{contents = ""}
)}
    4 : <CFString 0x12ed4740 [0x2f6eb38]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x12ed4da0 [0x2f6eb38]>{value = +320, type = kCFNumberSInt64Type}
    6 : <CFString 0x12ed48d0 [0x2f6eb38]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x12ed53c0 [0x2f6eb38]>{type = immutable dict, count = 5,
entries =>
    0 : <CFString 0x12ed4c10 [0x2f6eb38]>{contents = "CPT"} = <CFData 0x12f7ce50 [0x2f6eb38]>{length = 32, capacity = 32, bytes = 0xbadc4637a7c1885cd19a176755d1fecf ... 29f23ba15836dff2}
    1 : <CFString 0x12ed4f10 [0x2f6eb38]>{contents = "ICD9Disease"} = <CFData 0x12f7cea0 [0x2f6eb38]>{length = 32, capacity = 32, bytes = 0x7cf87b9141b2c154fda8fa973b11aba4 ... 471f47adf2a60a63}
    2 : <CFString 0x12ed50a0 [0x2f6eb38]>{contents = "ICD9Procedure"} = <CFData 0x12f7d040 [0x2f6eb38]>{length = 32, capacity = 32, bytes = 0x05909fa15f0da3d0d9a4329e31da816a ... fe44e8c0de14354b}
    3 : <CFString 0x12ed5230 [0x2f6eb38]>{contents = "MedicalCode"} = <CFData 0x12f7d090 [0x2f6eb38]>{length = 32, capacity = 32, bytes = 0x7d1d70878edb9c839f9586011ad1726f ... e7a60fcde779e490}
    6 : <CFString 0x12ed5250 [0x2f6eb38]>{contents = "HCPCS"} = <CFData 0x12f7d0e0 [0x2f6eb38]>{length = 32, capacity = 32, bytes = 0x9d052e1525b4357a1cd9b6c1d6481bbf ... 7ef40429b86137c0}
}

    7 : <CFString 0x1a16aa8 [0x2f6eb38]>{contents = "NSStoreUUID"} = <CFString 0x12ed3f70 [0x2f6eb38]>{contents = "EC3CEFE5-2414-431F-ABCE-C67DE6471874"}
    8 : <CFString 0x1a16948 [0x2f6eb38]>{contents = "NSStoreType"} = <CFString 0x1a16958 [0x2f6eb38]>{contents = "SQLite"}
    9 : <CFString 0x12ed4a60 [0x2f6eb38]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0xb8283f0 [0x2f6eb38]>{value = +3, type = kCFNumberSInt32Type}
    10 : <CFString 0x12ed4bf0 [0x2f6eb38]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x12ed5570 [0x2f6eb38]>{contents = "2"}
}
, reason=The model used to open the store is incompatible with the one used to create the store}, {
    metadata =     {
        NSPersistenceFrameworkVersion = 320;
        NSStoreModelVersionHashes =         {
            CPT = <badc4637 a7c1885c d19a1767 55d1fecf de75bb71 1198e89c 29f23ba1 5836dff2>;
            HCPCS = <9d052e15 25b4357a 1cd9b6c1 d6481bbf 3ee5bbef 7d67313a 7ef40429 b86137c0>;
            ICD9Disease = <7cf87b91 41b2c154 fda8fa97 3b11aba4 49984cd5 b8b4694e 471f47ad f2a60a63>;
            ICD9Procedure = <05909fa1 5f0da3d0 d9a4329e 31da816a 0f76d10e 54122f9c fe44e8c0 de14354b>;
            MedicalCode = <7d1d7087 8edb9c83 9f958601 1ad1726f 0ced7e49 2a139a20 e7a60fcd e779e490>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "EC3CEFE5-2414-431F-ABCE-C67DE6471874";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "The model used to open the store is incompatible with the one used to create the store";
}

2 个答案:

答案 0 :(得分:2)

您可以创建另一个名为ICD9的抽象实体,该实体从MedicalCode开始。然后ICD9DiseaseICD9Procedure将成为具体的子类。只需将公共属性移动到抽象ICD9类。

现在,您可以对所有ICD9个实体执行获取请求,并接收两个子实体。

答案 1 :(得分:0)

尝试删除在旧模型下创建的数据存储。它可能会在您的库目录中为您的应用程序。再次运行程序时,它应该重新创建存储而不会出现错误。

相关问题