Sha256: 0a39345827fdf02382b7a71482ef8b91ecd3ce99461ea6f5e96135c2c8d32386

Contents?: true

Size: 725 Bytes

Versions: 5

Compression:

Stored size: 725 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

        def skip_statement_cache?
          super || should_use_shard_key?
        end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-turntable-4.1.0 lib/active_record/turntable/active_record_ext/association.rb
activerecord-turntable-4.0.0 lib/active_record/turntable/active_record_ext/association.rb
activerecord-turntable-3.1.0 lib/active_record/turntable/active_record_ext/association.rb
activerecord-turntable-3.0.1 lib/active_record/turntable/active_record_ext/association.rb
activerecord-turntable-3.0.0 lib/active_record/turntable/active_record_ext/association.rb