aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-29 10:15:18 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-29 10:36:32 -0700
commitb2979117e0adad6f86370074237f57d96cc7c1c7 (patch)
tree8a48ba7f29c39bfd3fc8632d2aa4b778807dac79 /activerecord/lib/active_record/connection_adapters
parent2cc4b7f2978b3e2dac490894b5d548c7f58c587e (diff)
downloadrails-b2979117e0adad6f86370074237f57d96cc7c1c7.tar.gz
rails-b2979117e0adad6f86370074237f57d96cc7c1c7.tar.bz2
rails-b2979117e0adad6f86370074237f57d96cc7c1c7.zip
use inheritence to deal with custom methods
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb13
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb17
2 files changed, 20 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index ce6782aac7..4e770c37da 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -151,10 +151,10 @@ module ActiveRecord
#
# See also TableDefinition#column for details on how to create columns.
def create_table(table_name, options = {})
- table_definition = TableDefinition.new(self)
- table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
+ td = table_definition
+ td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
- yield table_definition if block_given?
+ yield td if block_given?
if options[:force] && table_exists?(table_name)
drop_table(table_name, options)
@@ -162,7 +162,7 @@ module ActiveRecord
create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
create_sql << "#{quote_table_name(table_name)} ("
- create_sql << table_definition.to_sql
+ create_sql << td.to_sql
create_sql << ") #{options[:options]}"
execute create_sql
end
@@ -534,6 +534,11 @@ module ActiveRecord
def options_include_default?(options)
options.include?(:default) && !(options[:null] == false && options[:default].nil?)
end
+
+ private
+ def table_definition
+ TableDefinition.new(self)
+ end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 0a2bacdb84..5078495ed8 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -27,12 +27,6 @@ module ActiveRecord
end
module ConnectionAdapters
- class TableDefinition
- def xml(*args)
- options = args.extract_options!
- column(args[0], 'xml', options)
- end
- end
# PostgreSQL-specific extensions to column definitions in a table.
class PostgreSQLColumn < Column #:nodoc:
# Instantiates a new PostgreSQL column definition in a table.
@@ -192,6 +186,13 @@ module ActiveRecord
# * <tt>:allow_concurrency</tt> - If true, use async query methods so Ruby threads don't deadlock;
# otherwise, use blocking query methods.
class PostgreSQLAdapter < AbstractAdapter
+ class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
+ def xml(*args)
+ options = args.extract_options!
+ column(args[0], 'xml', options)
+ end
+ end
+
ADAPTER_NAME = 'PostgreSQL'.freeze
NATIVE_DATABASE_TYPES = {
@@ -1024,6 +1025,10 @@ module ActiveRecord
[match_data[1], (rest.length > 0 ? rest : nil)]
end
end
+
+ def table_definition
+ TableDefinition.new(self)
+ end
end
end
end