Skip to content

Commit c3e583b

Browse files
committed
Handle VIEW defined in other database
Fixes #1027
1 parent 8e031b7 commit c3e583b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ def view_information(table_name)
580580
@view_information ||= {}
581581
@view_information[table_name] ||= begin
582582
identifier = SQLServer::Utils.extract_identifiers(table_name)
583-
view_info = select_one "SELECT * FROM INFORMATION_SCHEMA.VIEWS WITH (NOLOCK) WHERE TABLE_NAME = #{quote(identifier.object)}", "SCHEMA"
583+
information_query_table = identifier.database.present? ? "[#{identifier.database}].[INFORMATION_SCHEMA].[VIEWS]" : "[INFORMATION_SCHEMA].[VIEWS]"
584+
view_info = select_one "SELECT * FROM #{information_query_table} WITH (NOLOCK) WHERE TABLE_NAME = #{quote(identifier.object)}", "SCHEMA"
584585
if view_info
585586
view_info = view_info.with_indifferent_access
586587
if view_info[:VIEW_DEFINITION].blank? || view_info[:VIEW_DEFINITION].length == 4000

0 commit comments

Comments
 (0)