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?
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
|