class EcYear < ActiveRecord::Base default_scope :order => 'year desc' validates_uniqueness_of :year, :scope => :ec_major_school_id belongs_to :ec_major_school # 学生列表 has_many :ec_year_students, :dependent => :destroy # 毕业要求 has_many :ec_graduation_requirements, :dependent => :destroy # 培养目标 has_one :ec_training_objective, :dependent => :destroy # 课堂配置 has_many :ec_courses, :dependent => :destroy acts_as_attachable def prev_year ec_major_school.ec_years.find_by_year(year - 1) end end