将 Core Data 数据库保存到 sqlite 文件会丢失一些递归/循环关系信息

发布于 2024-09-28 21:54:37 字数 642 浏览 1 评论 0原文

我的 iPhone 文字游戏中有非常简单的循环(或自我反思)关系核心数据模型。 实体词与其自身具有一对多关系,指向相关词:

alt text

我使用 NSPersistentDocument 核心数据用于将单词导入 Core Data sqlite 数据库的 Mac OS X 模板应用程序。

导入数据后,我可以看到所有关系都已正确导入(每个单词至少有一个或多个相关单词)。

然而,将数据库保存到 sqlite 文件并再次重新打开后,相关单词指针会大量丢失(单词仍然存在,但关系消失 - NSLog 显示它们为空) 。有时相关词信息的丢失可能高达 50%。

当我将数据库存储为XML或二进制文件并重新打开它时,所有关系都被正确保存。

任何人都可以指出我为什么保存到sqlite文件会导致丢失当同一数据库的 XML 和二进制版本正确存储所有内容时,某些关系数据的变化如何?

我对 sqlite 很感兴趣,因为它在 iPhone 中使用时(内存)效率更高,当然产生的数据库文件大小要小得多。

I have very simple circular (or self-reflecting) relationship core data model in my iPhone word game.
Entity Word has one-to-many relationship to/with itself which points to related words:

alt text

I use NSPersistentDocument Core Data Mac OS X template application to import words to Core Data sqlite database.

After importing data I can see all relationships being imported correctly (every word has at least one or more related words to it).

However, after saving database to sqlite file and reopening it again there is huge loss of related words pointers (words are still there but relationships are gone - NSLog shows null for them). It could be sometimes up to 50% loss of related words information.

When I store my database as XML or binary file and reopen it, all relationships are being save properly.

Can anyone point me why saving to sqlite file can cause loss of some relationships data when XML and binary versions of the same database stores everything correctly?

I am interested in sqlite because it has opinion of being more (memory) efficient when using in iPhone and of course produces significantly smaller database file size.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月依秋水 2024-10-05 21:54:37

这不是一对多的关系。这是一种一对多的关系。它没有逆元。您可以看出这一点,因为线条的一端只有箭头。尝试添加逆关系,看看是否有帮助。

That is not a one-to-many relationship. That is a -to-many relationship. It has no inverse. You can tell this because there are only arrows on one end of the line. Try adding the inverse relationship and see if that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文