socialforge/app/models/contest_member_role.rb

23 lines
448 B
Ruby
Raw Normal View History

2016-12-22 10:01:37 +08:00
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