Module: ActiveRecordShards::DefaultSlavePatches::Rails41HasAndBelongsToManyBuilderExtension

Defined in:
lib/active_record_shards/default_slave_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-slave-by-default down from the parent now.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



110
111
112
113
114
115
# File 'lib/active_record_shards/default_slave_patches.rb', line 110

def self.included(base)
  base.class_eval do
    alias_method :through_model_without_inherit_default_slave_from_lhs, :through_model
    alias_method :through_model, :through_model_with_inherit_default_slave_from_lhs
  end
end

Instance Method Details

#through_model_with_inherit_default_slave_from_lhsObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/active_record_shards/default_slave_patches.rb', line 117

def through_model_with_inherit_default_slave_from_lhs
  model = through_model_without_inherit_default_slave_from_lhs
  def model.on_slave_by_default?
    left_reflection.klass.on_slave_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