私は4つのモデルを持っています:SchoolClass
、、、、:Timetable
Lesson
Reporting
# 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