24 lines
477 B
Ruby
24 lines
477 B
Ruby
class ContestMemberRole < ActiveRecord::Base
|
|
attr_accessible :role_id, :contest_member_id, :is_current
|
|
|
|
belongs_to :contest_member
|
|
belongs_to :role
|
|
|
|
#after_destroy :remove_member_if_empty
|
|
|
|
validates_presence_of :role
|
|
#validate :validate_role_member
|
|
|
|
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
|