简体   繁体   English

Rails应用中杂志存储的数据模型

[英]data model for magazine store in rails application

I want to create a rails 3.2.7 application for online magazine store. 我想为在线杂志商店创建Rails 3.2.7应用程序。 I design quick data model for this application but I'm not sure it is good or bad!? 我为此应用程序设计了快速的数据模型,但是我不确定它的好坏! I have Magazine table for all magazines, I have Product table for all version of specific Magazine and I have Page table for all pages of specific Product. 我有所有杂志的杂志表,我有特定杂志的所有版本的产品表,我有特定产品的所有页面的页面表。

Magazine has_many :Product

Product has_many :Pages and belongs_to :Magazine Product has_many :Pagesbelongs_to :Magazine

Page belong_to :product

I create this app but it has problems!! 我创建了这个程序,但是有问题! for example in routes.rb I use this code 例如在routes.rb中,我使用此代码

resources :magazines do
  resources :products do
    resources :pages
  end
end

but it's not work true !!!? 但这不是真的!!? I must change my data model or it's good for these application? 我必须更改数据模型还是对这些应用程序有好处?

It's important to separate the difference between routes and models. 区分路线和模型之间的差异很重要。 The embedded routes that you have created just alter the url that each model exists under. 您创建的嵌入式路由只会更改每个模型所在的URL。 It can be useful for keeping track of parameters that are useful for the page request. 这对于跟踪对页面请求有用的参数很有用。 You should make sure that you write migrations for all the relationships. 您应该确保为所有关系编写迁移。 Reading up on the relational associations in rails might be helpful. 仔细阅读Rails中关系关联可能会有所帮助。

But basically, you need to have migrations that add the id of the related item to it's associated field. 但基本上,您需要进行迁移,以将相关项目的ID添加到其关联字段中。 So you will end up adding a product_id field to your magazines table 因此,您最终将product_id字段添加到您的magazines表中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM