diff options
author | Matthew Draper <matthew@trebex.net> | 2017-06-17 09:58:12 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-17 09:58:12 +0930 |
commit | a1c8b4612373527333e59baca6d5fcf5598dd6eb (patch) | |
tree | 1fee3e832a74dc66f5c719449a1e004619030c8f /activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb | |
parent | c295296de3c07e48557b34062adb980ef5b1ec17 (diff) | |
parent | 7dbe62006da2576770babe92234467574834f305 (diff) | |
download | rails-a1c8b4612373527333e59baca6d5fcf5598dd6eb.tar.gz rails-a1c8b4612373527333e59baca6d5fcf5598dd6eb.tar.bz2 rails-a1c8b4612373527333e59baca6d5fcf5598dd6eb.zip |
Merge pull request #29431 from kamipo/fix_create_table_with_query_from_relation
Fix `create_table` with query from relation
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb index a4fecc4a8e..93f4529202 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb @@ -55,7 +55,7 @@ module ActiveRecord create_sql << "(#{statements.join(', ')})" if statements.present? add_table_options!(create_sql, table_options(o)) - create_sql << " AS #{@conn.to_sql(o.as)}" if o.as + create_sql << " AS #{to_sql(o.as)}" if o.as create_sql end @@ -114,6 +114,11 @@ module ActiveRecord sql end + def to_sql(sql) + sql = sql.to_sql if sql.respond_to?(:to_sql) + sql + end + def foreign_key_in_create(from_table, to_table, options) options = foreign_key_options(from_table, to_table, options) accept ForeignKeyDefinition.new(from_table, to_table, options) |