<commit_before>module Admin::Resources::DataTypes::BelongsToHelper

  def typus_belongs_to_field(attribute, form)
    association = @resource.reflect_on_association(attribute.to_sym)

    related = if defined?(set_belongs_to_context)
      set_belongs_to_context.send(attribute.pluralize.to_sym)
    else
      association.class_name.constantize
    end

    related_fk = association.foreign_key
    label_text = @resource.human_attribute_name(attribute)

    values = if related.respond_to?(:roots)
      expand_tree_into_select_field(related.roots, related_fk)
    else
      related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
    end

    attribute_id = "#{@resource.name.underscore}_#{attribute}_id".gsub('/', '_')

    render 'admin/templates/belongs_to',
           attribute: attribute,
           attribute_id: attribute_id,
           form: form,
           related_fk: related_fk,
           related: related,
           label_text: label_text.html_safe,<commit_msg>make sure the model exactly includes ancestry<commit_after>module Admin::Resources::DataTypes::BelongsToHelper

  def typus_belongs_to_field(attribute, form)
    association = @resource.reflect_on_association(attribute.to_sym)

    related = if defined?(set_belongs_to_context)
      set_belongs_to_context.send(attribute.pluralize.to_sym)
    else
      association.class_name.constantize
    end

    related_fk = association.foreign_key
    label_text = @resource.human_attribute_name(attribute)

    values = if related.respond_to?(:roots) && related.respond_to?(:ancestry_column)
      expand_tree_into_select_field(related.roots, related_fk)
    else
      related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
    end

    attribute_id = "#{@resource.name.underscore}_#{attribute}_id".gsub('/', '_')

    render 'admin/templates/belongs_to',
           attribute: attribute,
           attribute_id: attribute_id,
           form: form,
           related_fk: related_fk,
           related: related,
           label_text: label_text.html_safe,
{'fraction_non_alphanumeric': 0.09946627850557982, 'fraction_numerical': 0.0, 'mean_word_length': 3.623318385650224, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3137409', 'n_tokens_mistral': 658, 'n_tokens_neox': 643, 'n_words': 96}