Ruby on rails Rails有许多贯穿where子句的语句
我需要帮助才能有所成就 我的分析Ruby on rails Rails有许多贯穿where子句的语句,ruby-on-rails,Ruby On Rails,我需要帮助才能有所成就 我的分析是否可能有许多:klass,通过::subjects,但使用联接表AnalysisSubject中的属性进行过滤?或者我的模型应该不同 class Analysis has_many :analysis_subjects, dependent: :destroy has_many :subjects, through: :analysis_subjects has_many :klasses, -> { where(year: ??????, s
是否可能有许多:klass,通过::subjects
,但使用联接表AnalysisSubject中的属性进行过滤?或者我的模型应该不同
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
# There are year:integer and semester:integer attributes
# I want to use those attributes in my where clause for 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
如果重要的话,我使用的是Rails 5。谢谢您的帮助。是的,但您应该以另一种方式支付:您必须声明
中的中的有许多:筛选的分析主题
class Analysis
has_many :filtered_analisys_subjects, -> { where(year: x, semester: y }, foreign_key: "analysis_id", class_name: "AnalysisSubject", dependent: :destroy
has_many :subjects, through: :filtered_analysis_subjects
has_many :klasses, through: :subjects