<commit_before>class Legacy::Dream < Legacy::Base
  set_table_name 'dream'
  
  def corresponding_object
    find_corresponding_entry
  end
  def find_corresponding_entry
    Entry.where(created_at: self.created_at, title: self.title).first
  end
  def find_or_create_corresponding_entry
    entry = find_corresponding_entry
    if entry.blank?
      entry = Migration::DreamImporter.new(self).migrate
      entry.save!
    end
    entry
  end

  has_many :comments, {foreign_key: 'dreamId', class_name: "Legacy::Comment"}
  has_many :emotions, {foreign_key: 'dreamId', class_name: "Legacy::Emotion"}

  has_many :dream_images, {foreign_key: 'dreamId', class_name: 'Legacy::DreamImage'}
  has_many :images, {through: :dream_images}
  belongs_to :default_image, {foreign_key: 'defaultImageId', class_name: 'Legacy::Image'}

  belongs_to :user, {foreign_key: 'userId', class_name: 'Legacy::User'}
  belongs_to :privacy_option, {foreign_key: 'privacyOptionId', class_name: 'Legacy::PrivacyOption'}
  belongs_to :category, {foreign_key: 'catId', class_name: 'Legacy::Category'}
  belongs_to :legacy_user, {foreign_key: 'userId', class_name: 'Legacy::User'}
  belongs_to :theme_setting, {foreign_key: 'themeSettingId', class_name: 'Legacy::ThemeSetting'}

  has_many :user_series, {foreign_key: 'dreamId', class_name: 'UserSeries'}
  
  def main_image_id
    default_image.find_or_create_corresponding_image.id
  end
  
  def book_list
    user_series.map(&:option).map(&:title).join(',')
  end
  
  def dreamed_at
    dreamDate
  end
  def created_at
    enteredDate
  end
  def updated_at
    lastModified
  end
  
  def body
    description
  end
  
  def sharing_level
    case privacy_option.title
    when 'public'
      Entry::Sharing[:everyone]
    when 'anonymous'<commit_msg>so, main_image_id doesn't work if it's nil.  fixed that.<commit_after>class Legacy::Dream < Legacy::Base
  set_table_name 'dream'
  
  def corresponding_object
    find_corresponding_entry
  end
  def find_corresponding_entry
    Entry.where(created_at: self.created_at, title: self.title).first
  end
  def find_or_create_corresponding_entry
    entry = find_corresponding_entry
    if entry.blank?
      entry = Migration::DreamImporter.new(self).migrate
      entry.save!
    end
    entry
  end

  has_many :comments, {foreign_key: 'dreamId', class_name: "Legacy::Comment"}
  has_many :emotions, {foreign_key: 'dreamId', class_name: "Legacy::Emotion"}

  has_many :dream_images, {foreign_key: 'dreamId', class_name: 'Legacy::DreamImage'}
  has_many :images, {through: :dream_images}
  belongs_to :default_image, {foreign_key: 'defaultImageId', class_name: 'Legacy::Image'}

  belongs_to :user, {foreign_key: 'userId', class_name: 'Legacy::User'}
  belongs_to :privacy_option, {foreign_key: 'privacyOptionId', class_name: 'Legacy::PrivacyOption'}
  belongs_to :category, {foreign_key: 'catId', class_name: 'Legacy::Category'}
  belongs_to :legacy_user, {foreign_key: 'userId', class_name: 'Legacy::User'}
  belongs_to :theme_setting, {foreign_key: 'themeSettingId', class_name: 'Legacy::ThemeSetting'}

  has_many :user_series, {foreign_key: 'dreamId', class_name: 'UserSeries'}
  
  def main_image_id
    default_image.find_or_create_corresponding_image.id unless defaultImageId.nil?
  end
  
  def book_list
    user_series.map(&:option).map(&:title).join(',')
  end
  
  def dreamed_at
    dreamDate
  end
  def created_at
    enteredDate
  end
  def updated_at
    lastModified
  end
  
  def body
    description
  end
  
  def sharing_level
    case privacy_option.title
    when 'public'
      Entry::Sharing[:everyone]
    when 'anonymous'
{'fraction_non_alphanumeric': 0.10826446280991736, 'fraction_numerical': 0.0, 'mean_word_length': 4.847020933977456, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3484663', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1240, 'n_words': 259}