1
想象一下4款車型中的Rails 3.1嵌套屬性在Rails的
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
我怎麼能輸出排序列表的學生即將推出的測試 (按日期IE)(我猜有一個相當簡單的答案,但我一直在努力白費了一會兒)
我最好的猜測是一樣的東西:
@upcomingTests = @currstudent.tests.sort_by &:testDateTime
,但它似乎返回一個空數組
請張貼您的最佳嘗試和結果。 –