9个模型导轨之间的关联

问题描述 投票:-1回答:1

我有包含所有模型字段的架构,下面有9个模型我对这些模型之间的关联感到困惑。

Project
Team
User
Role
Report
Task
Component
Plan 
Process

我想在滑轨上创建红宝石模型,所以请根据滑轨向我提供关联谢谢

ruby-on-rails ruby database associations model-associations
1个回答
0
投票

如果您不严格遵循任何一种SDLC,也可以,但是至少可以在纸上粗略地绘制数据库图以了解顺序。必须至少有一个(或多个)顶级模型,该模型将不属于任何其他模型,例如用户。

作为初学者,您应该像这样创建支架:(假设用户仅具有first_name和last_name列)

  rails g scaffold user first_name:string last_name:string
  # This will create a migration, model file, CRUD (basic) views, controller with CRUD actions.
  # Go and edit the migration called [some_number]_create_users.rb if you need to.
  # run rails db:migrate and now you will have table added in schema and database too.

下一步(这是您的实际答案):

  # Create next entity with associations already created: (let's say it has only 1 column called deadline)
  rails g scaffold project deadline:datetime user:belongs_to

现在,它将为用户完成它所做的所有事情,而且还会创建关联(即,项目现在将属于用户。您可以在用户自己中添加has_many :projects)。希望您能如愿以偿。

© www.soinside.com 2019 - 2024. All rights reserved.