<commit_before>module Unidom::Product::Concerns::AsTargetProductAssociating

  extend ActiveSupport::Concern

  included do |includer|

    has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id
    has_many :source_products,             through:    :source_product_associatings,          source:      :source

  end

  module ClassMethods
  end

end<commit_msg>1, Improve the As Target Product Associating concern to add the #is_associated! method.<commit_after>module Unidom::Product::Concerns::AsTargetProductAssociating

  extend ActiveSupport::Concern

  included do |includer|

    has_many :source_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :target_id
    has_many :source_products,             through:    :source_product_associatings,          source:      :source

    #def is_associated?(source, due_to: nil, at: Time.now)
    #  source_product_associatings.source_is(source).product_association_coded_as(due_to).valid_at(now: at).alive.exists?
    #end

    def is_associated!(source, due_to: nil, at: Time.now, ordinal: 1)
      source_product_associatings.source_is(source).product_association_coded_as(due_to).valid_at(now: at).alive.first_or_create! ordinal: ordinal, opened_at: at
    end

  end

  module ClassMethods
  end

end
{'fraction_non_alphanumeric': 0.08753709198813056, 'fraction_numerical': 0.001483679525222552, 'mean_word_length': 4.814655172413793, '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': '2370309', 'n_tokens_mistral': 440, 'n_tokens_neox': 414, 'n_words': 83}