如何存储“关系”?两个 coredata 记录之间?

发布于 2024-10-06 10:48:17 字数 246 浏览 0 评论 0原文

我有两个实体: match 和 player ,我用中间表 matchplayer 设置了它们,因为玩家可以玩多场比赛,并且比赛将有多个玩家。我有可以分别添加、修改和删除比赛和玩家的视图,但我对如何填充匹配玩家实体感到困惑。我已经设置了没有属性但与比赛和玩家实体都有关系的匹配玩家实体。

我有一个管理比赛详细信息的视图,并从那里加载所有球员的表格视图,我可以在其中选择我想要“连接”到比赛的球员。但这就是我陷入困境的地方。我应该向匹配玩家实体添加什么来存储关系?

I have two entities: match and player , which I have set up with an intermediate table matchplayer as players can play multiple matches, and matches will have multiple players. I have views where I can add, amend and delete both matches and players separately, but I am confused about how to populate the matchplayer entity. I have set up the matchplayer entity with no attributes but with relationships to both the match and player entities.

I have a view managing match details, and from there it loads a tableview of all players where I can select the players I want to 'connect' to the match. But that's where I get stuck. What do I add to the matchplayer entity to store the relationship?

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

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

发布评论

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

评论(1

夜光 2024-10-13 10:48:18

您不需要仅仅为了维持关系而创建单独的实体。
您可以做的是维护从比赛实体到玩家实体的许多关系。
假设将该关系命名为playerInMatch。现在,您在比赛实体中插入的每个比赛的管理对象上下文,您可以使用 addPlayerInMatch: 方法(即创建模态类时自动生成的访问器方法)将多个玩家插入到此管理对象上下文中。
现在,在检索特定比赛期间,您可以通过其关系检索该比赛的完整球员集。如果需要,您可以使用它删除或添加任何球员到该集中。
(我已经向您简要解释了这个想法,希望您对使用核心数据关系有清楚的了解。如果您对核心数据不完全清楚,请查看以下教程:
http://cocoadevcentral.com/articles/000085.php

you don't need to create a separate entity just to maintain relationship.
What you can do is you maintain to many relationship from match entity to player entity.
Suppose name that relationship as playerInMatch. Now each managedObjectContext of match that you insert in match entity, you can insert multiple players to this managedObjectContext using addPlayerInMatch: method (i.e the accessor method that automatically gets generated when you created modal classes).
Now during retrival of a particular match , you can retrive a complete set of players of that match through its relationship.Using that you can delete or add any player to that set if you want to.
(I have briefly explained you the idea hoping you have a clear understanding of using core data relationship.If you are not perfectly clear with core data check out following tutorial:
http://cocoadevcentral.com/articles/000085.php

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