2016-12-22 10:01:37 +08:00
|
|
|
class ContestMemberRole < ActiveRecord::Base
|
2016-12-22 11:17:13 +08:00
|
|
|
attr_accessible :role_id, :contest_member_id, :is_current
|
|
|
|
|
2016-12-22 10:01:37 +08:00
|
|
|
belongs_to :contest_member
|
|
|
|
belongs_to :role
|
|
|
|
|
|
|
|
after_destroy :remove_member_if_empty
|
|
|
|
|
|
|
|
validates_presence_of :role
|
2016-12-22 15:08:15 +08:00
|
|
|
#validate :validate_role_member
|
2016-12-22 10:01:37 +08:00
|
|
|
|
|
|
|
def validate_role_member
|
|
|
|
errors.add :role_id, :invalid if role && !role.member?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def remove_member_if_empty
|
|
|
|
if contest_member.roles.empty?
|
|
|
|
contest_member.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|