帮助在 Core Data 中设置数据模型

发布于 2024-08-17 04:25:28 字数 2372 浏览 9 评论 0原文

我是核心数据新手,一直在尝试弄清楚如何建立我的数据模型。我制作了一个示例表来尝试展示我需要如何关联数据。

First Name Last Name Competitor Number Gender Team Competition Game Name     All Time high Competition Scores 
Jon         Doe            1          M  Gamers     January   Donkey Kong       Lvl 5         Level #         1 2 3 4
                                                                                       Trys to complete    1   0 1 3
                                                             Pac Man        8000               game 1   7000      
                                                                                              game 2   8500      
                                                                                              game 3   9000      
                                                       March  Donkey Kong         Lvl 5        Level #        
                                                                                             trys        
                                                             Pac Man                         Game 1        
                                                                                              Game 2        
                                                                                              Game 3        
     Bob        Smith       2              M Players   January    Asteroids        34000            Game 1    30000      
                                                                                              Game 2   20000      
                                                                                              Game 3   10000      
                                                              Pac Man          7000           Game 1       5000      
                                                                                              Game 2    4500      
                                                                                              Game 3    7000  

根据我所读到的内容,我认为我需要玩家、比赛、游戏名称的实体。玩家、比赛和游戏名称之间存在多对多关系,游戏名称和比赛之间也存在多对多关系。

然后是玩家的名字、姓氏、参赛者编号、性别、团队属性。比赛的属性将是月份(或名称),游戏名称的属性将是名称。

然后我陷入困境,我不知道历史最高分是否应该是 GameName 的一个属性,因为它需要与单个玩家相关联,并且玩家对于不同的游戏会有不同的高分。我需要能够跟踪像大金刚这样的游戏的尝试次数和最高级别,那么我会创建game1、game2、game3的属性吗?但其他游戏,比如吃豆人,我只关心最终得分。那么game1、game2、game3会是玩家还是游戏的属性吗?或者它本身应该是一个完整的实体?

感谢您的帮助。

I am new to Core Data, and have been trying to figure out how to set up my data model. I made a sample table to try and show how I need the data to relate.

First Name Last Name Competitor Number Gender Team Competition Game Name     All Time high Competition Scores 
Jon         Doe            1          M  Gamers     January   Donkey Kong       Lvl 5         Level #         1 2 3 4
                                                                                       Trys to complete    1   0 1 3
                                                             Pac Man        8000               game 1   7000      
                                                                                              game 2   8500      
                                                                                              game 3   9000      
                                                       March  Donkey Kong         Lvl 5        Level #        
                                                                                             trys        
                                                             Pac Man                         Game 1        
                                                                                              Game 2        
                                                                                              Game 3        
     Bob        Smith       2              M Players   January    Asteroids        34000            Game 1    30000      
                                                                                              Game 2   20000      
                                                                                              Game 3   10000      
                                                              Pac Man          7000           Game 1       5000      
                                                                                              Game 2    4500      
                                                                                              Game 3    7000  

From what I have read I think I need entities for Players, Competitions, GameNames. With To-Many relationships between players and competitions and gameNames, also a relationship between gameNames and competitions.

And then attributes of First Name, Last Name, competitor number, gender, team for players. Attributes for competition would be month (or name), Attributes for GameName would be name.

And then I get stuck I don't know if the all time high should be an attribute of GameName because it needs to be associated with the individual player, and players will have different high scores for different games. I need to be able to keep track of number of tries and the highest level for games like donkey kong, so would I make attributes of game1, game2, game3? But other games like pac-man I only care about the end score. So would game1, game2, game3 be attributes of the player or the game? or should it be an entire entity by itself?

thanks for any help.

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

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

发布评论

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

评论(1

乞讨 2024-08-24 04:25:28

至于你的具体问题:

那么我会创建game1、game2、game3的属性吗?但其他游戏,比如吃豆人,我只关心最终得分。那么game1、game2、game3会是玩家还是游戏的属性吗?或者它本身应该是一个完整的实体?

我建议您创建一个名为 Games 的对象类,并为其提供所需的属性,例如高分、最高级别等。

如果您有不同类型的游戏,您有两种选择:

  1. 您创建一个游戏层次结构,其中根游戏类包含所有公共属性,后代包括它们的细节 - 或者在这些情况下我更喜欢,

  2. 类型之间的变化不是太复杂也不是太多,我只是将属性放在一个类中并将它们用于需要它们的类型。

因此,在您的情况下,您首先需要以结构化的方式写下哪些游戏需要哪些属性,然后在类和子类与属性重载和冗余之间做出决定。

ps 这实际上不是一个核心数据问题,而是一个数据库设计问题。

你会发现,一旦你完成了这个结构,一切都会变得更加清晰......

As for your specific question:

so would I make attributes of game1, game2, game3? But other games like pac-man I only care about the end score. So would game1, game2, game3 be attributes of the player or the game? or should it be an entire entity by itself?

I would suggest you create an object class called Games and give it the attributes you need, such as highscore, highest level, etc.

If you have different types of Games you have two choices:

  1. you create a hierarchy of Games where the root Game-Class contains all the common attributes and the descendants include their specifics - or what I prefer in those cases,

  2. where the variations between the types are not too complicated and too many, I just put the attributes in one class and use them for the type where they are required.

So in your case you first need to write down in a structured way which attributes you need for which Games and then decide either between classes and subclasses vs attribute overload and redundancy.

ps this is actually not so much a core data issue but a DB-design.

You'll see, once you are done with this structuring everything becomes much clearer...

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