电子商店应用程序的模型关联
我正在使用 ruby on Rails 开发一个电子商店应用程序,我对模型关联有点困惑。如果有人能给我一些关于表格及其关联的想法,这会对我有所帮助。详细信息如下:
父表: =>类别, 场合, 类别下的热销商品
: => 男士, 女性, 男人下的孩子
: =>衬衫, 长裤
女式 : =>衬衫, 裤子, 裙子
儿童 : =>衬衫, 裤子
适合场合的 => 种族, 派对, 旅行, 随意的, 正式
热销中 =>Hot Deals Index
最后每个子表都会有产品索引。
谢谢你!
I'm developing an e-store app using ruby on rails and I'm a bit confused about the model associations. It would help me if someone could give me an idea about the tables and their associations. Here are the details:
Parent tables:
=>Categories,
occasions,
Hot Deals
Under Categories:
=>Men,
Women,
Kids
Under Men:
=>Shirts,
Trousers
Under Women:
=>Shirts,
Trousers,
Skirts
Under Kids:
=>Shirts,
Trousers
Under Occasions
=>Ethnic,
Party,
Travel,
Casual,
Formal
Under Hot Deals
=>Hot Deals Index
And lastly every last sub-table will have product index.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这样的事情,您通常会做的是构建一个与产品相关联的分类树,从而允许您将产品分组在一起。分类法和产品之间的多对多关系让您可以将产品与多个组关联起来,因此一件 T 恤可能位于“类别”>“类别”下。男士>衬衫以及场合>随意的。
然后迁移分类法/产品之间的连接表
并对其进行编辑。
从那里,您基本上将在数据库中创建 3 个分类单元,每个部分 1 个,然后创建分类法并构建子级别。创建产品时,请为产品和您的产品集分配正确的分类法。
种子文件可能看起来像...
然后,当您创建产品时,您可以将其与分类法关联起来,并使用该分类法来提取与其关联的产品列表。
What you would generally do with something like this is build a Taxonomy tree to that would be associated with the products, allowing you to group products together. A many to many relation between Taxonomy and Product let's you associate a product with multiple groups, so a T-Shirt might be under Categories > Men > Shirts as well as Occasion > Casual.
then a migration for the join table between taxonomy/product
and edit it
From there you would basically create in the database 3 Taxons, 1 for each of your sections, then create the Taxonomy and build out the sub levels. When you create your products, assign the right Taxonomy to the product and your set.
A seed file might look like...
Then when you create a Product, you can associate it with the Taxonomy and use that Taxonomy to pull up a list of products that are associated with it.