<commit_before>module ActiveMongoid
  module Associations
    class Many < Proxy

      delegate :avg, :max, :min, :sum, to: :criteria
      delegate :length, :size, to: :target
      delegate :count, to: :criteria
      delegate :first, :in_memory, :last, :reset, :uniq, to: :target

      def initialize(base, target, metadata)
        init(base, ActiveMongoid::Associations::Targets::Enumerable.new(target), metadata) do
        end
      end

      def <<(*args)
        objs = args.flatten
        return concat(objs) if objs.size > 1
        if objs = objs.first
          append(objs)
          objs.save if base.persisted?
        end
        self
      end
      alias :push :<<

      def build(attributes = {}, type = nil)
        obj = (type || klass).new(attributes)
        append(obj)
        yield(obj) if block_given?
        obj
      end
      alias :new :build

      def concat(objects)
        objs, inserts = [], []
        objects.each do |obj|
          next unless obj
          append(obj)
          save_or_delay(obj, objs, inserts) if base.persisted?
        end
        persist_delayed(objs, inserts)
        self
      end

      def purge
        unless __metadata__.destructive?<commit_msg>not saving when assigning attribute on the inverse<commit_after>module ActiveMongoid
  module Associations
    class Many < Proxy

      delegate :avg, :max, :min, :sum, to: :criteria
      delegate :length, :size, to: :target
      delegate :count, to: :criteria
      delegate :first, :in_memory, :last, :reset, :uniq, to: :target

      def initialize(base, target, metadata)
        init(base, ActiveMongoid::Associations::Targets::Enumerable.new(target), metadata) do
        end
      end

      def <<(*args)
        objs = args.flatten
        return concat(objs) if objs.size > 1
        if objs = objs.first
          append(objs)
          objs.save if base.persisted? && !_assigning?
        end
        self
      end
      alias :push :<<

      def build(attributes = {}, type = nil)
        obj = (type || klass).new(attributes)
        append(obj)
        yield(obj) if block_given?
        obj
      end
      alias :new :build

      def concat(objects)
        objs, inserts = [], []
        objects.each do |obj|
          next unless obj
          append(obj)
          save_or_delay(obj, objs, inserts) if base.persisted?
        end
        persist_delayed(objs, inserts)
        self
      end

      def purge
        unless __metadata__.destructive?
{'fraction_non_alphanumeric': 0.09923969587835134, 'fraction_numerical': 0.0008003201280512205, 'mean_word_length': 1.9904306220095693, 'pattern_counts': {'":': 0, '<': 13, '<?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': '2543235', 'n_tokens_mistral': 765, 'n_tokens_neox': 739, 'n_words': 213}