<commit_before>module StaticModel
  module Associations

    def self.included(klass)
      klass.extend MacroMethods
    end

    module MacroMethods

      def associations
        @associations ||= {}
      end

      def has_many(association_name, options = {})
        self.associations[association_name.to_sym] = HasManyAssociation.new(self, association_name.to_sym, {:foreign_key => "#{self.to_s.foreign_key}"}.merge(options))
      end 

    end


    class Association
      attr_reader :klass, :name, :options, :reflection_klass, :foreign_key

      def initialize(klass, name, options = {})
        @klass = klass
        @name = name
        @options = options
        @reflection_klass = Object.const_get(@options[:class_name] || @name.to_s.classify)
        @foreign_key = @options[:foreign_key]
        define_association_methods
      end

      def define_association_methods
        raise 'Should only use descendants of Association'
      end
    end

    class HasManyAssociation < Association

      def define_association_methods
        if @reflection_class.respond_to?(:scoped)
          @klass.module_eval <<-EOT
            def #{@name}
              #{@reflection_class}.scoped(:conditions => {:#{@foreign_key} => id})
            end
          EOT
        else
          @klass.module_eval <<-EOT
          def #{@name}
            #{@reflection_class}.send(:find_all_by_#{@foreign_key}, id)
          end
          EOT
        end
      end
    end

  end
end<commit_msg>Fixed HasMany define<commit_after>module StaticModel
  module Associations

    def self.included(klass)
      klass.extend MacroMethods
    end

    module MacroMethods

      def associations
        @associations ||= {}
      end

      def has_many(association_name, options = {})
        self.associations[association_name.to_sym] = HasManyAssociation.new(self, association_name.to_sym, {:foreign_key => "#{self.to_s.foreign_key}"}.merge(options))
      end 

    end


    class Association
      attr_reader :klass, :name, :options, :reflection_klass, :foreign_key

      def initialize(klass, name, options = {})
        @klass = klass
        @name = name
        @options = options
        @reflection_klass = Object.const_get(@options[:class_name] || @name.to_s.classify)
        @foreign_key = @options[:foreign_key]
        define_association_methods
      end

      def define_association_methods
        raise 'Should only use descendants of Association'
      end
    end

    class HasManyAssociation < Association

      def define_association_methods
        if reflection_klass.respond_to?(:scoped)
          klass.module_eval <<-EOT
            def #{name}
              #{reflection_klass}.scoped(:conditions => {:#{foreign_key} => id})
            end
          EOT
        else
          klass.module_eval <<-EOT
          def #{name}
            #{reflection_klass}.send(:find_all_by_#{foreign_key}, id)
          end
          EOT
        end
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.0943962641761174, 'fraction_numerical': 0.0, 'mean_word_length': 2.2992299229922994, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '5373784', 'n_tokens_mistral': 898, 'n_tokens_neox': 878, 'n_words': 183}