я иметь следующую структуру:Получить дополнительное значение атрибута '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
, сохраненные и связанные с этим ответом.
Существует способ доступа к output
без запроса непосредственно из моего AnswerTestCaseResult (то есть AnswerTestCaseResult.where(answer: answer, test_case: test_case)
)?