0
머리말 :이 질문은 매우 구체적입니다. 나는 이걸두고 내 머리를 짚어 봤는데 ... 나는이 사람을위한 전문가가 필요하다고 생각해.레일 4 - 복잡한 모델 관계
개념 : : "시험 응시자"는 객관식 질문에 답해야합니다 (보통 정답> 1). 사용자가 올바른 대답 (그림)을 선택한 다음 "제출"을 클릭하십시오.
셈 이죠 이런 식으로 :
내 문제 :이 수집에 내가 가장 좋은 방법을 모르고 (를 검색 결국 다음과)를 저장의 데이터 이런 종류의 일. 구체적으로 :
- 어떤 사용자가이 질문에 답하려고 했습니까?
- 사용자가 선택한 사진은 무엇입니까?
- 어떤 사용자 선택 사진이 옳았거나 틀렸습니까?
- 이 질문이 전체적으로 정확 했습니까? (예를 들어, 사용자는 부분적으로 만 옳다는?)
내 테이블 구조 :
users
id
===================================================
templates
id
prompt #"Which one needs baking?"
===================================================
choices #e.g., the image
id
name
image
===================================================
template_assignments #a join table between templates and choices
id
choice_id
template_id
correct #boolean - Is this image the correct response?
===================================================
responses #this is where I am LOST
id
user_id
template_id
--Not sure what to do with this table, maybe something like:
response_1
response_1_correct #boolean
etc....
overall_correct #boolean
-- Or would I need some other type of join table?
나의 관계 :
class Choice < ActiveRecord::Base
has_many :template_assignments
has_many :templates, :through => :template_assignments
end
class Template < ActiveRecord:Base
has_many :template_assignments, dependent: :destroy
has_many :choices, :through => :template_assignments
has_many :responses
accepts_nested_attributes_for :template_assignments, allow_destroy: true
end
class TemplateAssignment < ActiveRecord:Base
belongs_to :template
belongs_to :choice
end
class Response < ActiveRecord::Base
belongs_to :template
end
방법에 대한 제안 이 모델들 사이의 관계를 정의한다. 매우 도움이된다!
감사합니다.