我是Ruby on Rails的新手。我有一个相对简单的问题。我正在为用户建模。我希望用户能够拥有一个简短的“个人资料信息”,他们可以编辑这些信息并显示在他们的个人资料中。使ProfileMessage成为自己的模型是否有意义?或者,profile_message应该是包含用户设置的表中的一列吗?
我觉得整个模型对于一个字符串来说有点矫枉过正,如果我开始走这条路线,我最终将会遇到这么多模型,事情会变得很麻烦。
社区的想法是什么?
答案 0 :(得分:1)
I would keep your data structure as simple as possible when starting out. For a profile message, it doesn't make much sense to have it be it's own model. Only if profile_message were to later on have it's own set of attributes and behaviors, or if users could have more than one profile message...then I would consider moving it to a separate model.
答案 1 :(得分:0)
SQL中的表连接在您未正确使用它们时会消耗大量资源。在你的情况下,我认为仅为一个profile_message创建一个新模型不是一个好习惯。但是,它应该在用户/配置文件模型中实现。
这种方法可以更快地访问消息,另一方面,如果你使用整个表进行profile_message会使响应时间变慢,因为你需要每次在profileMessages表中查找它,这将是需要更多时间,具体取决于该表中的条目数。