<commit_before>class Category < ActiveRecord::Base

  SEARCHABLE_FIELDS = {
    :name => 10,
    :acronym => 5,
    :abbreviation => 5,
    :slug => 1,
  }

  validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.').fix_i18n
  validates_presence_of :name, :environment_id
  validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n
  belongs_to :environment

  validates_inclusion_of :display_color, :in => [ 1, 2, 3, 4, nil ]
  validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.').fix_i18n

  # Finds all top level categories for a given environment. 
  named_scope :top_level_for, lambda { |environment|
    {:conditions => ['parent_id is null and environment_id = ?', environment.id ]}
  }

  named_scope :on_level, lambda { |parent| {:conditions => {:parent_id => parent}} }

  named_scope :sub_categories, lambda { |category|
    {:conditions => ['categories.path LIKE ? AND categories.id != ?', "%#{category.slug}%", category.id]}
  }

  named_scope :sub_tree, lambda { |category|
    {:conditions => ['categories.path LIKE ?', "%#{category.slug}%"]}
  }

  acts_as_filesystem

  has_many :article_categorizations, :dependent => :destroy
  has_many :articles, :through => :article_categorizations
  has_many :comments, :through => :articles

  has_many :events, :through => :article_categorizations, :class_name => 'Event', :source => :article

  has_many :profile_categorizations, :dependent => :destroy
  has_many :profiles, :through => :profile_categorizations, :source => :profile
  has_many :enterprises, :through => :profile_categorizations, :source => :profile, :class_name => 'Enterprise'
  has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person'
  has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community'

  has_many :products, :through => :enterprises

  acts_as_having_image

  named_scope :from_types, lambda { |types|
    types.select{ |t| t.blank? }.empty? ?
      { :conditions => { :type => types } } :
      { :conditions => [ "type IN (?) OR type IS NULL", types.reject{ |t| t.blank? } ] }
  }

  def recent_people(limit = 10)
    self.people.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit)
  end

  def recent_enterprises(limit = 10)
    self.enterprises.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit)
  end

  def recent_communities(limit = 10)
    self.communities.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit)
  end<commit_msg>[postgres-tests] Removing unnecessary dependent => destroy from category<commit_after>class Category < ActiveRecord::Base

  SEARCHABLE_FIELDS = {
    :name => 10,
    :acronym => 5,
    :abbreviation => 5,
    :slug => 1,
  }

  validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.').fix_i18n
  validates_presence_of :name, :environment_id
  validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n
  belongs_to :environment

  validates_inclusion_of :display_color, :in => [ 1, 2, 3, 4, nil ]
  validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.').fix_i18n

  # Finds all top level categories for a given environment. 
  named_scope :top_level_for, lambda { |environment|
    {:conditions => ['parent_id is null and environment_id = ?', environment.id ]}
  }

  named_scope :on_level, lambda { |parent| {:conditions => {:parent_id => parent}} }

  named_scope :sub_categories, lambda { |category|
    {:conditions => ['categories.path LIKE ? AND categories.id != ?', "%#{category.slug}%", category.id]}
  }

  named_scope :sub_tree, lambda { |category|
    {:conditions => ['categories.path LIKE ?', "%#{category.slug}%"]}
  }

  acts_as_filesystem

  has_many :article_categorizations
  has_many :articles, :through => :article_categorizations
  has_many :comments, :through => :articles

  has_many :events, :through => :article_categorizations, :class_name => 'Event', :source => :article

  has_many :profile_categorizations
  has_many :profiles, :through => :profile_categorizations, :source => :profile
  has_many :enterprises, :through => :profile_categorizations, :source => :profile, :class_name => 'Enterprise'
  has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person'
  has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community'

  has_many :products, :through => :enterprises

  acts_as_having_image

  named_scope :from_types, lambda { |types|
    types.select{ |t| t.blank? }.empty? ?
      { :conditions => { :type => types } } :
      { :conditions => [ "type IN (?) OR type IS NULL", types.reject{ |t| t.blank? } ] }
  }

  def recent_people(limit = 10)
    self.people.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit)
  end

  def recent_enterprises(limit = 10)
    self.enterprises.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit)
  end

  def recent_communities(limit = 10)
    self.communities.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit)
  end
{'fraction_non_alphanumeric': 0.15260259371113874, 'fraction_numerical': 0.008527269497246403, 'mean_word_length': 4.658291457286432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 98, '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': '5592943', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1870, 'n_words': 463}