'を介しにhas_many' から余分な属性値を取得します。私のanswer
モデルで私は、以下の構造を有する関連
を:
class Answer < ApplicationRecord
has_many :answer_test_case_results
has_many :test_cases_result, through: :answer_test_case_results, source: :test_case
end
マイanswer_test_case_result
:
class AnswerTestCaseResult < ApplicationRecord
belongs_to :answer
belongs_to :test_case
def get_output
output
end
end
マイanswer_test_case_result
モデルがあり余分な属性は、output
という名前です。私のanswer
モデルではoutput
と私のtest_cases_result
という関係からアクセスしたいと思いますが、この属性は、test_case
オブジェクトのみが保存され、この回答に関連付けられています。
私のAnswerTestCaseResult(つまり、AnswerTestCaseResult.where(answer: answer, test_case: test_case)
)から直接クエリなしでoutput
にアクセスする方法がありますか?