mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure using proper engine for Arel::Table
This commit is contained in:
parent
4796be33a4
commit
a115b5d79a
3 changed files with 15 additions and 3 deletions
|
@ -1510,11 +1510,17 @@ module ActiveRecord #:nodoc:
|
|||
end
|
||||
|
||||
def active_relation_table(table_name_alias = nil)
|
||||
Arel::Table.new(table_name, :as => table_name_alias)
|
||||
Arel::Table.new(table_name, :as => table_name_alias, :engine => active_relation_engine)
|
||||
end
|
||||
|
||||
def active_relation_engine
|
||||
@active_relation_engine ||= Arel::Sql::Engine.new(self)
|
||||
@active_relation_engine ||= begin
|
||||
if self == ActiveRecord::Base
|
||||
Arel::Table.engine
|
||||
else
|
||||
connection_handler.connection_pools[name] ? Arel::Sql::Engine.new(self) : superclass.active_relation_engine
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -130,7 +130,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def table
|
||||
@table ||= Arel::Table.new(@klass.table_name, Arel::Sql::Engine.new(@klass))
|
||||
@table ||= Arel::Table.new(@klass.table_name, :engine => @klass.active_relation_engine)
|
||||
end
|
||||
|
||||
def primary_key
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require "cases/helper"
|
||||
require 'models/entrant'
|
||||
require 'models/bird'
|
||||
|
||||
# So we can test whether Course.connection survives a reload.
|
||||
require_dependency 'models/course'
|
||||
|
@ -82,4 +83,9 @@ class MultipleDbTest < ActiveRecord::TestCase
|
|||
assert_equal "Ruby Development", Course.find(1).name
|
||||
assert_equal "Ruby Developer", Entrant.find(1).name
|
||||
end
|
||||
|
||||
def test_arel_table_engines
|
||||
assert_not_equal Entrant.active_relation_engine, Course.active_relation_engine
|
||||
assert_equal Entrant.active_relation_engine, Bird.active_relation_engine
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue