Module: ActiveRecordShards::DefaultReplicaPatches::Rails41HasAndBelongsToManyBuilderExtension

Defined in:
lib/active_record_shards/default_replica_patches.rb

Overview

in rails 4.1+, they create a join class that’s used to pull in records for HABTM. this simplifies the hell out of our existence, because all we have to do is inerit on-replica-by-default down from the parent now.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



166
167
168
169
170
171
# File 'lib/active_record_shards/default_replica_patches.rb', line 166

def self.included(base)
  base.class_eval do
    alias_method :through_model_without_inherit_default_replica_from_lhs, :through_model
    alias_method :through_model, :through_model_with_inherit_default_replica_from_lhs
  end
end

Instance Method Details

#through_model_with_inherit_default_replica_from_lhsObject



173
174
175
176
177
178
179
180
181
182
# File 'lib/active_record_shards/default_replica_patches.rb', line 173

def through_model_with_inherit_default_replica_from_lhs
  model = through_model_without_inherit_default_replica_from_lhs
  def model.on_replica_by_default?
    left_reflection.klass.on_replica_by_default?
  end

  # also transfer the sharded-ness of the left table to the join model
  model.not_sharded unless model.left_reflection.klass.is_sharded?
  model
end