Fix count on a separate connection (fixes #18359)
Previosly count and other AR calculations would convert column_name_for_operation to sql on a default Arel::Table.engine (AR::Base) connection. That could lead to trouble if current model has a connection to a different adapter or Base connection is inaccessible.
This commit is contained in:
parent
5d28c6b5b8
commit
824862807b
@ -392,7 +392,7 @@ def lookup_cast_type(sql_type) # :nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def column_name_for_operation(operation, node) # :nodoc:
|
def column_name_for_operation(operation, node) # :nodoc:
|
||||||
node.to_sql
|
visitor.accept(node, collector).value
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -93,6 +93,13 @@ def test_connection
|
|||||||
assert_not_equal Entrant.arel_engine.connection, Course.arel_engine.connection
|
assert_not_equal Entrant.arel_engine.connection, Course.arel_engine.connection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_count_on_custom_connection
|
||||||
|
ActiveRecord::Base.remove_connection
|
||||||
|
assert_equal 1, College.count
|
||||||
|
ensure
|
||||||
|
ActiveRecord::Base.establish_connection :arunit
|
||||||
|
end
|
||||||
|
|
||||||
unless in_memory_db?
|
unless in_memory_db?
|
||||||
def test_associations_should_work_when_model_has_no_connection
|
def test_associations_should_work_when_model_has_no_connection
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user