<commit_before>#
# A user's relationship to pages
#
# "user_participations" is the join table:
#   user has many pages through user_participations
#   page has many users through user_participations
#
module UserExtension::Pages

  ##
  ## ASSOCIATIONS
  ##

  def self.included(base)
    base.instance_eval do
      has_many :participations, :class_name => 'UserParticipation',
        :after_add => :update_tag_cache, :after_remove => :update_tag_cache,
        :dependent => :destroy

      has_many :pages, :through => :participations do
        def pending
          find(:all, :conditions => ['resolved = ?',false], :order => 'happens_at' )
        end
        def recent_pages(options={})
          find(:all, {:order => 'user_participations.changed_at DESC', :limit => 15}.merge(options))
        end
      end

      has_many :pages_owned, :class_name => 'Page', :as => :owner, :dependent => :nullify

      named_scope(:most_active_on, lambda do |site, time|
        ret = {
          :joins => "
            INNER JOIN user_participations
              ON users.id = user_participations.user_id
            INNER JOIN pages
              ON pages.id = user_participations.page_id AND<commit_msg>dependent nullify for created_by and updated_by<commit_after>#
# A user's relationship to pages
#
# "user_participations" is the join table:
#   user has many pages through user_participations
#   page has many users through user_participations
#
module UserExtension::Pages

  ##
  ## ASSOCIATIONS
  ##

  def self.included(base)
    base.instance_eval do
      has_many :participations, :class_name => 'UserParticipation',
        :after_add => :update_tag_cache, :after_remove => :update_tag_cache,
        :dependent => :destroy

      has_many :pages, :through => :participations do
        def pending
          find(:all, :conditions => ['resolved = ?',false], :order => 'happens_at' )
        end
        def recent_pages(options={})
          find(:all, {:order => 'user_participations.changed_at DESC', :limit => 15}.merge(options))
        end
      end

      has_many :pages_owned, :class_name => 'Page', :as => :owner, :dependent => :nullify
      has_many :pages_created, :class_name => 'Page', :as => :created_by, :dependent => :nullify
      has_many :pages_updated, :class_name => 'Page', :as => :updated_by, :dependent => :nullify

      named_scope(:most_active_on, lambda do |site, time|
        ret = {
          :joins => "
            INNER JOIN user_participations
              ON users.id = user_participations.user_id
            INNER JOIN pages
              ON pages.id = user_participations.page_id AND
{'fraction_non_alphanumeric': 0.11363636363636363, 'fraction_numerical': 0.0015151515151515152, 'mean_word_length': 2.9183976261127595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '3609233', 'n_tokens_mistral': 817, 'n_tokens_neox': 768, 'n_words': 204}