Sha256: 32e1743770ea0d133917262879bf7ec6d1f3c8d685afb6a479082b0ddf8493d4

Contents?: true

Size: 990 Bytes

Versions: 1

Compression:

Stored size: 990 Bytes

Contents

class User < ActiveRecord::Base
  belongs_to :employer

  belongs_to :manages_company, :class_name => "Company"
  counter_culture :manages_company, :column_name => "managers_count"

  belongs_to :has_string_id
  counter_culture :has_string_id

  belongs_to :has_non_pk_id
  counter_culture :has_non_pk_id

  has_many :reviews
  accepts_nested_attributes_for :reviews, :allow_destroy => true

  if Rails.version >= "5.0.0"
    has_paper_trail
  end

  default_scope do
    if _default_scope_enabled
      query = joins("LEFT OUTER JOIN companies ON users.company_id = companies.id")
      if Rails.version < "5.0.0"
        query = query.uniq
      else
        query = query.distinct
      end
    else
      if Rails.version < "4.0.0"
        scoped
      else
        all
      end
    end
  end

  class << self
    attr_accessor :_default_scope_enabled

    def with_default_scope
      @_default_scope_enabled = true
      yield
      @_default_scope_enabled = false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
counter_culture-2.2.2 spec/models/user.rb