[英]Active Record database Organization
I'm creating my first web app as an assignment. 我正在创建我的第一个Web应用程序作为作业。 I am writing my project proposal and part of the proposal is to create a schema.
我正在编写项目建议,该建议的一部分是创建模式。
The app concept is simple, it's creating a workout log, where users can create, edit and delete workouts all kept in an organized log. 该应用程序的概念很简单,它创建了一个锻炼日志,用户可以在其中创建,编辑和删除所有保存在有组织的日志中的锻炼。
I am having trouble thinking about the best way to structure the database so when a user wants to fetch a specific workout, it comes with all exercises and their results. 我在思考构造数据库的最佳方法时遇到了麻烦,因此当用户想要获取特定的锻炼时,它将附带所有锻炼及其结果。
So far I've come up with this layout. 到目前为止,我已经提出了这种布局。 I guess workouts.exercises.results would gather the correct information, but I wanted to know if their was a tidier way to organize this data as it is my first time and I am trying to create this using best practices.
我猜想training.exercises.results会收集正确的信息,但是我想知道它们是否是整理此数据的更简洁的方法,这是我第一次这样做,因此我尝试使用最佳实践来创建它。
column name 栏名
id ID
name 名称
user_id 用户身份
updated_at 的updated_at
column name 栏名
id ID
name 名称
workout_id workout_id
updated_at 的updated_at
column name 栏名
id ID
exercise_id exercise_id
workout_id workout_id
sets 套
reps 代表
duration 持续时间
updated_at 的updated_at
As per my understanding, Workouts has many exercises
, Exercise has one Result
. 据我了解,
Workouts has many exercises
, Exercise has one Result
。
If yes, then you don't need workout id in result table. 如果是,则在结果表中不需要锻炼ID。
For fetching the records by workout
, use the following code: 要通过
workout
获取记录,请使用以下代码:
w = Workout.find(workout_id)
w.exercises.each do |e|
puts "Exercise=#{e.name} and result = #{e.result}}
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.