<commit_before># == Schema Information
#
# Table name: rooms
#
#  id         :integer          not null, primary key
#  name       :string(255)
#  address    :text
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class Room < ActiveRecord::Base
  attr_accessible :name, :address

  has_many :users
  has_many :check_lists, :dependent => :delete_all
  has_many :check_list_items, :dependent => :delete_all
  has_many :poll_lists, :dependent => :delete_all
  has_many :poll_list_items, :dependent => :delete_all
  has_many :chore_lists, :dependent => :delete_all
  has_many :chore_list_items, :dependent => :delete_all
  has_many :chore_list_recurring_items, :dependent => :delete_all
  has_many :bills, :dependent => :delete_all
  has_many :notes, :dependent => :delete_all
  has_many :pictures, :dependent => :delete_all

  validates_presence_of :name
  
  GUEST_ROOM_ID = 1
  
  def self.all_empty
    empty = []
    Room.all.each do |room|
      if room.users.blank?
        empty.push room unless room.id == Room::GUEST_ROOM_ID
      end
    end
    empty
  end

end<commit_msg>Add before_destroy on room to unassign users.<commit_after># == Schema Information
#
# Table name: rooms
#
#  id         :integer          not null, primary key
#  name       :string(255)
#  address    :text
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class Room < ActiveRecord::Base
  attr_accessible :name, :address

  has_many :users 
  has_many :check_lists, :dependent => :delete_all
  has_many :check_list_items, :dependent => :delete_all
  has_many :poll_lists, :dependent => :delete_all
  has_many :poll_list_items, :dependent => :delete_all
  has_many :chore_lists, :dependent => :delete_all
  has_many :chore_list_items, :dependent => :delete_all
  has_many :chore_list_recurring_items, :dependent => :delete_all
  has_many :bills, :dependent => :delete_all
  has_many :notes, :dependent => :delete_all
  has_many :pictures, :dependent => :delete_all
  before_destroy :unassign_user_room

  validates_presence_of :name
  
  GUEST_ROOM_ID = 1
  
  def self.all_empty
    empty = []
    Room.all.each do |room|
      if room.users.blank?
        empty.push room unless room.id == Room::GUEST_ROOM_ID
      end
    end
    empty
  end

  private

  def unassign_user_room
    User.where(room_id: self.id).each do |user|
      user.room_id = nil
      user.save
    end
  end

end
{'fraction_non_alphanumeric': 0.0953355155482815, 'fraction_numerical': 0.0032733224222585926, 'mean_word_length': 3.373881932021467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6155684', 'n_tokens_mistral': 844, 'n_tokens_neox': 830, 'n_words': 207}