Sha256: c114ef7579f5cf307aed970b3fed2c524842943a773e7c97798daa36ccbd4560

Contents?: true

Size: 887 Bytes

Versions: 4

Compression:

Stored size: 887 Bytes

Contents

require "active_record/associations"

module ActiveRecord::Turntable
  module ActiveRecordExt
    module Association
      include ShardingCondition

      def self.prepended(mod)
        ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :foreign_shard_key
      end

      protected

        # @note Override to pass shard key conditions
        def target_scope
          return super unless should_use_shard_key?

          scope = klass.where(
            klass.turntable_shard_key =>
              owner.send(foreign_shard_key)
          )
          super.merge!(scope)
        end

      private

        if Util.ar52_or_later?
          def skip_statement_cache?(scope)
            super || should_use_shard_key?
          end
        else
          def skip_statement_cache?
            super || should_use_shard_key?
          end
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-turntable-4.4.1 lib/active_record/turntable/active_record_ext/association.rb
activerecord-turntable-4.4.0 lib/active_record/turntable/active_record_ext/association.rb
activerecord-turntable-4.3.0 lib/active_record/turntable/active_record_ext/association.rb
activerecord-turntable-4.2.0 lib/active_record/turntable/active_record_ext/association.rb