Sha256: f6447a1f10e3f378c8e50aadd36f925cea8c344de76d7201633c41e5a189b1b8

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module DbCharmer
  module ActiveRecord
    module RelationMethod

      def self.extended(base)
        class << base
          alias_method_chain :relation, :db_charmer
          alias_method_chain :arel_engine, :db_charmer
        end
      end

      # Create a relation object and initialize its default connection
      def relation_with_db_charmer(*args, &block)
        relation_without_db_charmer(*args, &block).tap do |rel|
          rel.db_charmer_connection = self.retrieve_connection
          rel.db_charmer_enable_slaves = self.db_charmer_slaves.any?
          rel.db_charmer_connection_is_forced = !db_charmer_top_level_connection?

          # The relation may have been memoized at a time when the schema
          # was different. Reset the schema here to use the value saved in the model
          # (which might have been updated previously when fetching the connection).
          rel.table.name = self.table_name
        end
      end

      # Use the model itself an engine for Arel, do not fall back to AR::Base
      def arel_engine_with_db_charmer(*)
        self
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yam-db-charmer-1.7.4.0 lib/db_charmer/rails3/active_record/relation_method.rb