私はこの課題を抱えています。特定の部門 ID と特定のコース年度に一致するすべてのコースを取得したいと考えています。前者は達成されていますが、後者の達成には問題があります。
#course.rb
has_and_belongs_to_many :departments
#department.rb
has_and_belongs_to_many :courses
[編集]
#student.rb
belongs_to :department
has_many :courses
ここまで持って
## Fetch Courses that Match that studentdept
@coursedept = Course.all(:include => :departments , :conditions => ["departments.id = ? and Courses.year = ? " , studentdept,courseyear]
上記は空の結果セットを返します。コース基準がなくても機能します。
そこのコース基準にどのように適合するのが最善ですか。さまざまなバリエーションを試しました