<commit_before>module PolarisResource
  module Associations
    class HasOneAssociation < Association

      # The initializer calls out to the superclass' initializer and then
      # sets the options particular to itself.
      def initialize(owner, association, settings = {})
        super

        # The foreign key is used to generate the url for the association
        # request when the association is transformed into a relation.
        # The default is to use the class of the owner object with an '_id'
        # suffix.
        @options[:foreign_key] ||= "#{@owner.class.to_s.underscore}_id".to_sym

        # The primary key is used in the generated url for the target. It
        # defaults to :id.
        @options[:primary_key] ||= :id

        # @association_class stores the class of the association, constantized
        # from the named association (i.e. Automobile, Car, CarClub)
        @association_class = @options[:class_name].constantize
      end

      def with_filter(filter)
        HasOneAssociation.new(@owner, @association, :target => @target, :filters => @filters.dup.push(filter), :options => @options)
      end

      # When loading the target, the primary key is first checked. If the
      # key is nil, then an nil is returned. Otherwise, the target
      # is requested at the generated url. For a has_one :meeting
      # association on a class called Course, the generated url might look
      # like this: /meetings?course_id=1, where the 1 is the primary key.
      def load_target!
        if primary_key = @owner.send(@options[:primary_key])
          Relation.new(@association.to_s.classify.constantize).where(@options[:foreign_key] => primary_key).limit(1).first
        end
      end

    end
  end
end<commit_msg>Fixing class_name option for has_one association<commit_after>module PolarisResource
  module Associations
    class HasOneAssociation < Association

      # The initializer calls out to the superclass' initializer and then
      # sets the options particular to itself.
      def initialize(owner, association, settings = {})
        super

        # The foreign key is used to generate the url for the association
        # request when the association is transformed into a relation.
        # The default is to use the class of the owner object with an '_id'
        # suffix.
        @options[:foreign_key] ||= "#{@owner.class.to_s.underscore}_id".to_sym

        # The primary key is used in the generated url for the target. It
        # defaults to :id.
        @options[:primary_key] ||= :id

        # @association_class stores the class of the association, constantized
        # from the named association (i.e. Automobile, Car, CarClub)
        if @options[:class_name]
          @association_class = @options[:class_name].constantize
        else
          @association_class = @association
        end
      end

      def with_filter(filter)
        HasOneAssociation.new(@owner, @association, :target => @target, :filters => @filters.dup.push(filter), :options => @options)
      end

      # When loading the target, the primary key is first checked. If the
      # key is nil, then an nil is returned. Otherwise, the target
      # is requested at the generated url. For a has_one :meeting
      # association on a class called Course, the generated url might look
      # like this: /meetings?course_id=1, where the 1 is the primary key.
      def load_target!
        if primary_key = @owner.send(@options[:primary_key])
          Relation.new(@association_class.to_s.classify.constantize).where(@options[:foreign_key] => primary_key).limit(1).first
        end
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.0813162904541746, 'fraction_numerical': 0.0016317650258362796, 'mean_word_length': 2.7956656346749225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6015592', 'n_tokens_mistral': 994, 'n_tokens_neox': 965, 'n_words': 370}