<commit_before>module ResourceTools::Association

  extend ActiveSupport::Concern

  included do
  end

  module ClassMethods

    def has_associated(association)
      self.instance_eval %Q{
        belongs_to :#{association}, :foreign_key => :id_#{association}_tmp
        attr_accessor :#{association}_id, :#{association}_uuid

        before_validation do
          associate = #{association.to_s.classify}.with_uuid(#{association}_uuid).first! unless #{association}_uuid.blank?
          associate ||= #{association.to_s.classify}.for_lims(id_lims).with_id(#{association}_id).first! unless #{association}_id.blank?
          self.#{association}= associate unless associate.blank?
        end

      }
    end

  end
end<commit_msg>Missing record exceptions are more informative<commit_after>module ResourceTools::Association

  extend ActiveSupport::Concern

  included do
  end

  module ClassMethods

    def has_associated(association)
      self.instance_eval %Q{
        belongs_to :#{association}, :foreign_key => :id_#{association}_tmp
        attr_accessor :#{association}_id, :#{association}_uuid

        before_validation do
          uuid_error = "No #{association} with uuid '%s'"
          id_error   = "No #{association} for '%s' with_id '%s'"

          associate = #{association.to_s.classify}.with_uuid(#{association}_uuid).first or
            raise(ActiveRecord::RecordNotFound, uuid_error % #{association}_uuid) unless #{association}_uuid.blank?
          associate ||= #{association.to_s.classify}.for_lims(id_lims).with_id(#{association}_id).first or
            raise(ActiveRecord::RecordNotFound, id_error % [id_lims,#{association}_id]) unless #{association}_id.blank?
          self.#{association}= associate unless associate.nil?
        end

      }
    end

  end
end
{'fraction_non_alphanumeric': 0.11549139367018323, 'fraction_numerical': 0.0, 'mean_word_length': 3.66839378238342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5980986', 'n_tokens_mistral': 540, 'n_tokens_neox': 533, 'n_words': 101}