1
가 레일에서 4 개 모델을 상상 레일의 속성 3.1중첩이
class Student < ActiveRecord::Base
has_many :memberships
has_many :courses, :through => :memberships
has_many :tests, :through => :courses
end
class Membership < ActiveRecord::Base
belongs_to :student
belongs_to :course
end
class Course < ActiveRecod::Base
has_many :tests
has_many :students, :through => :memberships
end
class Test < ActiveRecord::Base
belongs_to :course
end
어떻게 I 출력 학생의 향후 테스트 의 (날짜 즉) 정렬 된 목록 (I 상당히 간단한 대답이 같은데요, 하지만 난 잠시 동안 헛된)에 노력했습니다
내 추측은 뭔가 같다 :
@upcomingTests = @currstudent.tests.sort_by &:testDateTime
하지만, 빈 배열을 반환 것으로 보인다
최상의 시도와 결과를 게시하십시오. –