2014-12-02 14:41:36 +08:00
class CourseGroup < ActiveRecord :: Base
# attr_accessible :title, :body
belongs_to :course
2014-12-04 22:02:10 +08:00
has_many :members
2014-12-04 19:09:10 +08:00
has_many :memberships , :class_name = > 'Member'
has_many :member_principals , :class_name = > 'Member' ,
:include = > :principal ,
:conditions = > " #{ Principal . table_name } .type='Group' OR ( #{ Principal . table_name } .type='User' AND #{ Principal . table_name } .status= #{ Principal :: STATUS_ACTIVE } ) "
has_many :principals , :through = > :member_principals , :source = > :principal
has_many :users , :through = > :members
2014-12-02 14:41:36 +08:00
before_destroy :set_member_nil
attr_accessible :name
2014-12-10 18:40:04 +08:00
validates :name , :presence = > true , :length = > { :maximum = > 20 } ,
:uniqueness = > { case_sensitive : false }
2014-12-02 14:41:36 +08:00
def set_member_nil
if self . members && self . members . count > 0
self . members . update_all ( " course_group_id = 0 " )
end
end
end