Sha256: d5a5c4297c2a56f0b73dd48e47254b9ed435579e286b419067e59f5779726a24

Contents?: true

Size: 912 Bytes

Versions: 5

Compression:

Stored size: 912 Bytes

Contents

module DbCharmer
  module ActiveRecord
    module RelationMethod

      def self.extended(base)
        class << base
          alias_method_chain :relation, :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.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

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yam-db-charmer-1.7.4.14 lib/db_charmer/rails3/active_record/relation_method.rb
yam-db-charmer-1.7.4.13 lib/db_charmer/rails3/active_record/relation_method.rb
yam-db-charmer-1.7.4.10 lib/db_charmer/rails3/active_record/relation_method.rb
yam-db-charmer-1.7.4.9 lib/db_charmer/rails3/active_record/relation_method.rb
yam-db-charmer-1.7.4.8 lib/db_charmer/rails3/active_record/relation_method.rb