<commit_before>module Edition::RelatedPolicies
  extend ActiveSupport::Concern

  include Edition::RelatedDocuments

  included do
    has_many :related_policies, through: :related_documents, source: :latest_edition, class_name: 'Policy'
  end

  def published_related_policies
    related_policies.published
  end

  # Ensure that when we set policy ids we don't remove other types of edition from the array
  def related_policy_ids=(policy_ids)
    policy_ids = Array.wrap(policy_ids).reject(&:blank?)
    new_policies = policy_ids.map {|id| Policy.find(id).document }
    other_related_documents = self.related_documents.reject { |document| document.latest_edition.is_a?(Policy) }

    self.related_documents = other_related_documents + new_policies
  end

  def can_be_related_to_policies?
    true<commit_msg>Fix bug with published related policies.<commit_after>module Edition::RelatedPolicies
  extend ActiveSupport::Concern

  include Edition::RelatedDocuments

  included do
    has_many :related_policies, through: :related_documents, source: :latest_edition, class_name: 'Policy'
    has_many :published_related_policies, through: :related_documents, source: :published_edition, class_name: 'Policy'
  end

  # Ensure that when we set policy ids we don't remove other types of edition from the array
  def related_policy_ids=(policy_ids)
    policy_ids = Array.wrap(policy_ids).reject(&:blank?)
    new_policies = policy_ids.map {|id| Policy.find(id).document }
    other_related_documents = self.related_documents.reject { |document| document.latest_edition.is_a?(Policy) }

    self.related_documents = other_related_documents + new_policies
  end

  def can_be_related_to_policies?
    true
{'fraction_non_alphanumeric': 0.07922535211267606, 'fraction_numerical': 0.0, 'mean_word_length': 5.433962264150943, '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': '351961', 'n_tokens_mistral': 527, 'n_tokens_neox': 511, 'n_words': 122}