Module: ActiveRecord::Turntable::ActiveRecordExt::Association::SingularAssociationExt

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_record/turntable/active_record_ext/association.rb

Instance Method Summary collapse

Instance Method Details

#find_target_with_turntableObject



58
59
60
61
62
# File 'lib/active_record/turntable/active_record_ext/association.rb', line 58

def find_target_with_turntable
  if record = turntable_scope(scope).take
    set_inverse_instance record
  end
end

#get_records_with_turntableObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_record/turntable/active_record_ext/association.rb', line 36

def get_records_with_turntable
  if reflection.scope_chain.any?(&:any?) ||
      scope.eager_loading? ||
      klass.current_scope ||
      klass.default_scopes.any? ||
      should_use_shard_key? # OPTIMIZE: Use bind values if cachable scope

    return turntable_scope(scope).limit(1).to_a
  end

  conn = klass.connection
  sc = reflection.association_scope_cache(conn, owner) do
    ActiveRecord::StatementCache.create(conn) { |params|
      as = ActiveRecord::Associations::AssociationScope.create { params.bind }
      target_scope.merge(as.scope(self, conn)).limit(1)
    }
  end

  binds = ActiveRecord::Associations::AssociationScope.get_bind_values(owner, reflection.chain)
  sc.execute binds, klass, klass.connection
end