23 lines
448 B
Ruby
23 lines
448 B
Ruby
|
class ContestMemberRole < ActiveRecord::Base
|
||
|
belongs_to :contest_member
|
||
|
belongs_to :role
|
||
|
# attr_accessible :title, :body
|
||
|
|
||
|
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
|