배경 : 나는 선수들과 함께 응용 프로그램을 가지고 있는데, 각 운동 선수 (선수 모델)는 운동을 할당받을 수 있습니다 (운동 모델, 모델을 통한 workout_assignment).질량 지정 방법 개별적으로 편집
문제점 : 처음에는 workout_assignment를 통해 많은 운동을하는 운동 선수와의 연결을 사용하고 workout_assignment를 통해 많은 운동 선수가있는 운동이 나에게 잘 작동한다고 생각했습니다. 그러나 내가 이런 식으로한다면 50 명의 운동 선수에게 운동을 할당하면 모두 동일한 운동 기록을 참조하게됩니다. 나는 코치 (운동을 배정한 사람)가 50 명의 운동 선수에게 동일한 운동을 할당 할 수 있기를 원하지만 원하는 경우 (운동 선수를 위해 맞춤 설정) 하나씩 변경할 수 있어야합니다. 누구든지이 문제에 접근하는 방법에 대한 조언을 받았습니까? 운동 사본 50 부를 작성하고 각각을 사용자에게 할당해야합니까, 별도의 운동이있을 경우 모델을 통해 실제로 workout_assignment가 필요한가요?
조언 해 주셔서 감사합니다.
스키마
create_table "athletes", :force => true do |t|
t.string "name"
t.string "username"
t.string "password"
t.string "sport"
t.text "notes"
t.integer "coach_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
end
create_table "coaches", :force => true do |t|
t.string "name"
t.string "username"
t.string "password"
t.string "address"
t.string "city"
t.string "state"
t.string "zipcode"
t.string "phone"
t.string "sports"
t.integer "experience"
t.datetime "created_at"
t.datetime "updated_at"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
end
create_table "workout_assignments", :force => true do |t|
t.integer "athlete_id"
t.integer "workout_id"
t.date "date_assigned"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "workouts", :force => true do |t|
t.string "name"
t.string "type"
t.integer "coach_id"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "category_id"
end
모델 조합 :
class Athlete < ActiveRecord::Base
belongs_to :coach
has_many :workouts, :through => :workout_assignments
end
class Workout < ActiveRecord::Base
has_many :athletes, :through => :workout_assignments
belongs_to :category
end
class WorkoutAssignment < ActiveRecord::Base
belongs_to :workout
belongs_to :athlete
end
class Coach < ActiveRecord::Base
has_many :athletes
has_many :workouts
end
운동 기록은 어떻게 연관되어 있습니까?여러분의 모델과 모든 has_many' 또는'belongs_to' 관계를 가진 스키마를 게시하거나'athlete_id','workout_id' 및 다른 필드를 모두 게시 할 수 있다면 도움이 될 것입니다. –
좋아, 원래 게시물에 추가했습니다. 나는 이것을 설정하는 가장 좋은 방법으로 고심하고 있으므로 선수들에게 운동을 정상적으로 할당 할 수는 있지만 한 번에 여러 선수에게 할당 할 수도 있습니다. (그러나 그 후에 개별적으로 변경할 수 있습니다.) 도와 줘서 고마워! –
이것을 레일스상의 루비보다는 데이터베이스의 것으로 태그를 붙일 수 있습니다. – tybro0103