I've a couple of questions.
我有几个问题。
I'm making a rudimentary CMS with Rails to get a hang of it. It's going to have pages, blog posts that belong to certain categories (think wordpress) which admins can add/edit from admin area. I'm a bit shaky on databases and relationships between them, though.
我正在使用Rails创建一个基本的CMS来获取它。它将包含属于特定类别的页面,博客文章(想想wordpress),管理员可以从管理区域添加/编辑。不过,我对数据库和它们之间的关系有点不稳定。
I want admins to have full access to the pages and blog posts; blog posts and pages must be separate entities - pages can go in the menu, while blog posts show up on the blog.
我希望管理员能够完全访问页面和博客帖子;博客帖子和页面必须是单独的实体 - 页面可以放在菜单中,而博客帖子则显示在博客上。
How do I organize this as far as the database relationships go so it's all nice and proper?
我如何组织这个数据库关系,所以这一切都很好和正确?
pages belongs to and has many categories posts belongs to and has many categories?
页面属于并且有很多类别的帖子属于并且有很多类别?
Also, in what scenarios is the use of add_index() necessary/advisable?
此外,在什么情况下使用add_index()必要/可行?
From a bird's eye view, what principles would you keep in mind when creating databases for a CMS?
从鸟瞰图中,在为CMS创建数据库时,您会记住哪些原则?
2 个解决方案
#1
2
think about it in terms of relations:
从关系的角度考虑:
- a page belongs_to a category
- a category has_many pages
- if you want to add more categories to a page, you can think about tags (check for acts_as_taggable_on gem), it's simpler and clearer to manage ;)
一个页面属于一个类别
一个类别has_many页面
如果你想为页面添加更多类别,你可以考虑标签(检查acts_as_taggable_on gem),管理起来更简单,更清晰;)
finally, add indexes on columns where you'll need faster/frequent lookups
最后,在需要更快/频繁查找的列上添加索引
#1
2
think about it in terms of relations:
从关系的角度考虑:
- a page belongs_to a category
- a category has_many pages
- if you want to add more categories to a page, you can think about tags (check for acts_as_taggable_on gem), it's simpler and clearer to manage ;)
一个页面属于一个类别
一个类别has_many页面
如果你想为页面添加更多类别,你可以考虑标签(检查acts_as_taggable_on gem),管理起来更简单,更清晰;)
finally, add indexes on columns where you'll need faster/frequent lookups
最后,在需要更快/频繁查找的列上添加索引