构建这些关系的最佳方式是什么?是否参加 HABTM?

发布于 2024-09-27 02:18:50 字数 1123 浏览 7 评论 0原文

只是寻找一些关于如何在我正在制作的应用程序中构建我的关系的建议。我有以下模型:

activity # golf, karaoke
event    # golf competition followed by all-night karaoke boat party
post     # write-up of the golf and karaoke event mentioned above
gallery  # photos from the golf and karaoke event

问题 1

  • 每个事件可以涉及多个活动
  • 每个活动可以关联多个活动

我是否需要在活动和事件之间建立一个habtm


问题 2

  • 每个事件都可以在多篇博客文章中进行报道
  • 一个帖子可以报道更多内容不止一个事件

我应该在事件和帖子之间使用 habtm 吗?


问题 3

  • 每个帖子可以包含来自多个图库的图像
  • 图库可以包含在多个图库中不是一篇文章

这是另一个习惯吗?


问题 4 - 可以想象,管理员可能希望将 1 组或多组照片与 1 个或多个事件链接,而不创建博客文章将所有内容联系在一起。声明画廊和活动之间的habtm关系是否明智?


奖励积分:具有这么多习惯的应用程序是否可能比在相同模型之间强制执行一对多关系的应用程序慢?在应用程序变得过于复杂之前,是否建议限制其拥有的习惯关系数量?

提前致谢

Just looking for some advice on how to structure my relationships in an app that I'm making. I have the following models:

activity # golf, karaoke
event    # golf competition followed by all-night karaoke boat party
post     # write-up of the golf and karaoke event mentioned above
gallery  # photos from the golf and karaoke event

Question 1

  • each event can involve more than one activity
  • each activity can be associated with more than one event

Do I need a habtm between activity and event?


Question 2

  • each event can be reported in more than one blog post
  • a post can report on more than one event

Should I use a habtm between event and post?


Question 3

  • each post can include images from more than one gallery
  • a gallery can be included in more than one post

Is this another habtm?


Question 4 - It's conceivable that the admins might want to link 1 or more sets of photos with 1 or more events, without creating a blog post to tie everything together. Would it be advisable to declare a habtm relationship between galleries and events?


For bonus points: Is an app with this many habtm's likely to be slower than one which enforces one-to-many relationships between the same models? Is there a suggested limit to the number of habtm relationships an app an have before it becomes too complex?

Thanks in advance

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

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

发布评论

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

评论(1

简单 2024-10-04 02:18:50

所有情况都需要 habtm。它遵循您的规范。你只能想知道你是否真的需要这样的关系。看看http://en.wikipedia.org/wiki/You_ain%27t_gonna_need_it“YAGNI ”。
在开发过程中我也不会考虑速度。当您的应用程序速度缓慢时,请添加缓存。

All cases needs habtm. It follows from your specyfication. You can only wonder if you really need such relations. Look at http://en.wikipedia.org/wiki/You_ain%27t_gonna_need_it "YAGNI".
I would not also think about speed during developement. When your app will be slow, add caching.

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