<commit_before>class Entity < ActiveRecord::Base
  has_many :people, :before_add => :set_entity_type

  #TODO: TGF DELETE THESE WHEN DONE WITH REFACTORING
  has_many :places, :order => 'created_at ASC', :before_add => :set_entity_type
  has_one  :current_place, :class_name => 'Place', :order => 'created_at DESC'

  #TODO: TGF CHANGE PLACE_TEMP TO PLACE WHEN REFACTORING COMPLETE
  has_one :place_temp, :class_name => "Place"
  has_one :person_temp, :class_name => "Person"

  has_many :entities_locations, :foreign_key => 'entity_id', :order => 'entity_location_type_id, created_at DESC'
  has_many :locations, :through => :entities_locations

  # TODO: SERIOUS DEBT, Nothing enforces just one primary location
  has_one :primary_entities_location, 
    :class_name => 'EntitiesLocation', 
    :foreign_key => 'entity_id', 
    :conditions => [ "primary_yn_id = ?", ExternalCode.yes_id ],
    :order => 'created_at DESC'
  
  # Just grabbing the most recent phone here. Not supporting multiples yet.
  has_one :primary_phone_entities_location, 
    :class_name => 'EntitiesLocation', 
    :foreign_key => 'entity_id', 
    :conditions => [ "location_type_id = ?", Code.find_by_code_name_and_code_description('locationtype', "Telephone Location Type").id],
    :order => 'created_at DESC'
  
  has_and_belongs_to_many :races, 
    :class_name => 'ExternalCode', 
    :join_table => 'people_races', 
    :association_foreign_key => 'race_id', 
    :order => 'code_description'

  attr_protected :entity_type
  validates_presence_of :entity_type
  validates_associated :people<commit_msg>Fixes bug where 'single' phone numbers created in R2 were showing up multiple times in R3.<commit_after>class Entity < ActiveRecord::Base
  has_many :people, :before_add => :set_entity_type

  #TODO: TGF DELETE THESE WHEN DONE WITH REFACTORING
  has_many :places, :order => 'created_at ASC', :before_add => :set_entity_type
  has_one  :current_place, :class_name => 'Place', :order => 'created_at DESC'

  #TODO: TGF CHANGE PLACE_TEMP TO PLACE WHEN REFACTORING COMPLETE
  has_one :place_temp, :class_name => "Place"
  has_one :person_temp, :class_name => "Person"

  has_many :entities_locations, :foreign_key => 'entity_id', 
                                :select => "DISTINCT ON (entity_id, entity_location_type_id, primary_yn_id, location_type_id) *", 
                                :order => 'entity_id, entity_location_type_id, primary_yn_id, location_type_id, created_at DESC'
  has_many :locations, :through => :entities_locations

  # TODO: SERIOUS DEBT, Nothing enforces just one primary location
  has_one :primary_entities_location, 
    :class_name => 'EntitiesLocation', 
    :foreign_key => 'entity_id', 
    :conditions => [ "primary_yn_id = ?", ExternalCode.yes_id ],
    :order => 'created_at DESC'
  
  # Just grabbing the most recent phone here. Not supporting multiples yet.
  has_one :primary_phone_entities_location, 
    :class_name => 'EntitiesLocation', 
    :foreign_key => 'entity_id', 
    :conditions => [ "location_type_id = ?", Code.find_by_code_name_and_code_description('locationtype', "Telephone Location Type").id],
    :order => 'created_at DESC'
  
  has_and_belongs_to_many :races, 
    :class_name => 'ExternalCode', 
    :join_table => 'people_races', 
    :association_foreign_key => 'race_id', 
    :order => 'code_description'

  attr_protected :entity_type
  validates_presence_of :entity_type
  validates_associated :people
{'fraction_non_alphanumeric': 0.10870193697600462, 'fraction_numerical': 0.0005782017924255566, 'mean_word_length': 4.607779578606159, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, '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': '4314987', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1125, 'n_words': 266}