socialforge/app/models/contest_member_role.rb

24 lines
477 B
Ruby
Raw Normal View History

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
2016-12-24 16:29:10 +08:00
#after_destroy :remove_member_if_empty
2016-12-22 10:01:37 +08:00
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