<commit_before>module ActiveMongoid
  module Associations
    class Metadata < Hash

      delegate :primary_key_default, :foreign_key_default, :stores_foreign_key?, :macro, to: :relation

      def as
        self[:as]
      end

      def as?
        !!as
      end

      def initialize(properties = {})
        merge!(properties)
      end

      def autosave
        self[:autosave]
      end

      def autosave?
        !!autosave
      end

      def builder(base, object)
        relation.builder(base, self, object)
      end

      def criteria(object, type = nil)
        query = relation.criteria(self, object, type)
        # order ? query.order_by(order) : query
        query
      end

      def key
        relation.stores_foreign_key? ? foreign_key : primary_key
      end

      def foreign_key
        @foreign_key ||= determine_foreign_key
      end

      def foreign_key_setter
        @foreign_key_setter ||= "#{foreign_key}="
      end

      def type_setter
        @type_setter ||= "#{type}="
      end

      def determine_key<commit_msg>added default order option<commit_after>module ActiveMongoid
  module Associations
    class Metadata < Hash

      delegate :primary_key_default, :foreign_key_default, :stores_foreign_key?, :macro, to: :relation

      def as
        self[:as]
      end

      def as?
        !!as
      end

      def initialize(properties = {})
        merge!(properties)
      end

      def autosave
        self[:autosave]
      end

      def autosave?
        !!autosave
      end

      def builder(base, object)
        relation.builder(base, self, object)
      end

      def order
        self[:order]
      end

      def criteria(object, type = nil)
        query = relation.criteria(self, object, type)
        if order
          query = query.respond_to?(:order_by) ? query.order_by(order) : query.order(order)
        end
        query
      end

      def key
        relation.stores_foreign_key? ? foreign_key : primary_key
      end

      def foreign_key
        @foreign_key ||= determine_foreign_key
      end

      def foreign_key_setter
        @foreign_key_setter ||= "#{foreign_key}="
      end

      def type_setter
        @type_setter ||= "#{type}="
      end

      def determine_key
{'fraction_non_alphanumeric': 0.08156966490299823, 'fraction_numerical': 0.0, 'mean_word_length': 1.9353169469598965, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4729038', 'n_tokens_mistral': 705, 'n_tokens_neox': 663, 'n_words': 164}