Module: ActiveRecordShards::DefaultReplicaPatches::ActiveRelationPatches

Defined in:
lib/active_record_shards/default_replica_patches.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/active_record_shards/default_replica_patches.rb', line 131

def self.included(base)
  [:calculate, :exists?, :pluck, :load].each do |m|
    ActiveRecordShards::DefaultReplicaPatches.wrap_method_in_on_replica(false, base, m)
  end

  if ActiveRecord::VERSION::MAJOR == 4
    # `where` and `having` clauses call `create_binds`, which will use the primary connection
    ActiveRecordShards::DefaultReplicaPatches.wrap_method_in_on_replica(false, base, :create_binds, force_on_replica: true)
  end

  ActiveRecordShards::DefaultReplicaPatches.wrap_method_in_on_replica(false, base, :to_sql, force_on_replica: true)
end

Instance Method Details

#on_replica_unless_txObject



144
145
146
# File 'lib/active_record_shards/default_replica_patches.rb', line 144

def on_replica_unless_tx
  @klass.on_replica_unless_tx { yield }
end