Module: DbCharmer::ActiveRecord::RelationMethod

Defined in:
lib/db_charmer/rails3/active_record/relation_method.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
9
# File 'lib/db_charmer/rails3/active_record/relation_method.rb', line 5

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

Instance Method Details

#relation_with_db_charmer(*args, &block) ⇒ Object

Create a relation object and initialize its default connection



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/db_charmer/rails3/active_record/relation_method.rb', line 12

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