0
我有4種型號驗證:SchoolClass
,Timetable
,Lesson
,Reporting
:的Rails 3 - 通過幾個型號
# class_code :string(255)
class SchoolClass < ActiveRecord::Base
has_many :timetables
end
class Timetable < ActiveRecord::Base
belongs_to :school_class
has_many :lessons
end
class Lesson < ActiveRecord::Base
belongs_to :timetable
has_one :reporting
end
# report_type :string(255)
class Reporting < ActiveRecord::Base
belongs_to :lesson
validates :report_type,
:presence => true,
:inclusion => { :in => %w(homework checkpoint)}
end
我如何可以驗證每個SchoolClass
只能有1 Reporting
,類型爲 「關卡」?