<commit_before>class Registrar < ActiveRecord::Base
  belongs_to :country
  has_many :domains, :dependent => :restrict_with_error
  has_many :ns_sets
  has_many :epp_users
  has_many :users

  validates :name, :reg_no, :address, :country, presence: true
  validates :name, :reg_no, uniqueness: true


  def domain_transfers
    at = DomainTransfer.arel_table
    DomainTransfer.where(
      at[:transfer_to_id].eq(id).or(
        at[:transfer_from_id].eq(id)
      )
    )
  end

  def to_s
    name
  end

  class << self
    def search_by_query(query)
      res = search(name_or_reg_no_cont: query).result
      res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v[:name]} (#{v[:reg_no]})" } }
    end
  end
end
<commit_msg>Prevent resgistrar deleting when children exist<commit_after>class Registrar < ActiveRecord::Base
  belongs_to :country
  has_many :domains, :dependent => :restrict_with_error
  has_many :epp_users, :dependent => :restrict_with_error
  has_many :users, :dependent => :restrict_with_error

  validates :name, :reg_no, :address, :country, presence: true
  validates :name, :reg_no, uniqueness: true


  def domain_transfers
    at = DomainTransfer.arel_table
    DomainTransfer.where(
      at[:transfer_to_id].eq(id).or(
        at[:transfer_from_id].eq(id)
      )
    )
  end

  def to_s
    name
  end

  class << self
    def search_by_query(query)
      res = search(name_or_reg_no_cont: query).result
      res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v[:name]} (#{v[:reg_no]})" } }
    end
  end
end

{'fraction_non_alphanumeric': 0.12805662805662807, 'fraction_numerical': 0.0, 'mean_word_length': 3.6279761904761907, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '5902962', 'n_tokens_mistral': 576, 'n_tokens_neox': 558, 'n_words': 123}