aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/speaker.rb
blob: 0ed9cdd08cd32ce2911068d70c7cdb2c4542ea65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Speaker < ActiveRecord::Base
  belongs_to :user
  belongs_to :discussion
  
  validates_uniqueness_of :user_id, :scope => :discussion_id
  validates :user, :discussion, :presence => true
  
  after_destroy :destroy_discussion
  
  private
  
  def destroy_discussion
    self.discussion.destroy unless self.discussion.speakers.any?
  end
  
end