I need help with the following problem:
Is it possible that my Analysis model has_many :klasses, through: :subjects
, but being filtered by attributes of the join_table AnalysisSubject? Or should my modeling be any different?
class Analysis
has_many :analysis_subjects, dependent: :destroy
has_many :subjects, through: :analysis_subjects
has_many :klasses, -> { where(year: ??????, semester: ??????), through: :subjects
end
class AnalysisSubject
belongs_to :analysis
belongs_to :subject
# Existem os atributos year e semester nessa join_table
# Eu gostaria de usá-los na query feita em analysis.klasses
end
class Subject
has_many :klasses
has_many :analysis_subjects
has_many :analyses, through: :analysis_subjects
end
class Klass
belongs_to :subject
end
I'm using Rails 5 if it's important to know. Thank you in advance for your help.