khiav223577/active_model_cachers

View on GitHub
lib/active_model_cachers/patches/patch_rails_3.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true
module ActiveModelCachers
  module ActiveRecord
    module Extension
      # define #find_by for Rails 3
      def find_by(*args)
        where(*args).order('').first
      end
    end
  end
end

module ActiveRecord
  module Transactions
    if not method_defined?(:transaction_include_any_action?)
      def transaction_include_any_action?(fire_on)
        fire_on.any?{|s| transaction_include_action?(s) }
      end
    end
  end
end

module ActiveRecord
  module Associations
    # = Active Record Associations
    #
    # This is the root class of all associations ('+ Foo' signifies an included module Foo):
    #
    #   Association
    #     SingularAssociation
    #       HasOneAssociation
    #         HasOneThroughAssociation + ThroughAssociation
    #       BelongsToAssociation
    #         BelongsToPolymorphicAssociation
    #     CollectionAssociation
    #       HasAndBelongsToManyAssociation
    #       HasManyAssociation
    #         HasManyThroughAssociation + ThroughAssociation
    class Association #:nodoc:
      alias_method :scope, :scoped
    end
  end
end

class ActiveModelCachers::ColumnValueCache
  def pluck_columns(object, relation, columns)
    object.connection.select_all(relation.select(columns)).map(&:values)
  end
end