<commit_before>require_dependency 'profile'

# FIXME move to core
class Profile

  def has_admin? person
    return unless person
    person.has_permission? 'edit_profile', self
  end

end

class Profile

  # cannot use :order because of months/years named_scope
  has_many :orders, class_name: 'OrdersPlugin::Sale', foreign_key: :profile_id
  has_many :sales, class_name: 'OrdersPlugin::Sale', foreign_key: :profile_id
  has_many :purchases, class_name: 'OrdersPlugin::Purchase', foreign_key: :consumer_id

  has_many :ordered_items, through: :orders, source: :items, order: 'name ASC'

  has_many :sales_consumers, through: :sales, source: :consumer
  has_many :purchases_consumers, through: :sales, source: :consumer

  has_many :sales_profiles, through: :sales, source: :profile
  has_many :purchases_profiles, through: :sales, source: :profile

  def sales_all_consumers
    consumers = self.sales_consumers.order 'name ASC'<commit_msg>orders: apply has_many to community<commit_after>require_dependency 'profile'
require_dependency 'community'

([Profile] + Profile.descendants).each do |subclass|
subclass.class_eval do

  # cannot use :order because of months/years named_scope
  has_many :orders, class_name: 'OrdersPlugin::Sale', foreign_key: :profile_id
  has_many :sales, class_name: 'OrdersPlugin::Sale', foreign_key: :profile_id
  has_many :purchases, class_name: 'OrdersPlugin::Purchase', foreign_key: :consumer_id

  has_many :ordered_items, through: :orders, source: :items, order: 'name ASC'

  has_many :sales_consumers, through: :sales, source: :consumer
  has_many :purchases_consumers, through: :sales, source: :consumer

  has_many :sales_profiles, through: :sales, source: :profile
  has_many :purchases_profiles, through: :sales, source: :profile

end
end

class Profile

  def sales_all_consumers
    consumers = self.sales_consumers.order 'name ASC'
{'fraction_non_alphanumeric': 0.09808102345415778, 'fraction_numerical': 0.0, 'mean_word_length': 6.2471042471042475, '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': '6939385', 'n_tokens_mistral': 640, 'n_tokens_neox': 598, 'n_words': 168}