aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-07-27 17:06:22 +0000
committerJamis Buck <jamis@37signals.com>2005-07-27 17:06:22 +0000
commit369d0543380d302fb4b4fc30d4f6d52f07f9c0b6 (patch)
tree9af5bc70b2cf000b90c2182ffce88c64cd1c17b0
parent9fad3251d3d11f32fad01c820b6d1d72e2329976 (diff)
downloadrails-369d0543380d302fb4b4fc30d4f6d52f07f9c0b6.tar.gz
rails-369d0543380d302fb4b4fc30d4f6d52f07f9c0b6.tar.bz2
rails-369d0543380d302fb4b4fc30d4f6d52f07f9c0b6.zip
Fix create_table so that id column is implicitly added [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1949 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb7
-rw-r--r--activerecord/test/migration_test.rb13
3 files changed, 16 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index d23b69aa16..b76c107cfe 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fix create_table so that id column is implicitly added [Rick Olson]
+
* Default sequence names for Oracle changed to #{table_name}_seq, which is the most commonly used standard. In addition, a new method ActiveRecord::Base#set_sequence_name allows the developer to set the sequence name per model. This is a non-backwards-compatible change -- anyone using the old-style "rails_sequence" will need to either create new sequences, or set: ActiveRecord::Base.set_sequence_name = "rails_sequence" #1798
* OCIAdapter now properly handles synonyms, which are commonly used to separate out the schema owner from the application user #1798
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 7a680c3101..532d582565 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -384,7 +384,6 @@ module ActiveRecord
create_sql << "#{name} ("
create_sql << table_definition.to_sql
create_sql << ") #{options[:options]}"
-
execute create_sql
end
@@ -518,9 +517,7 @@ module ActiveRecord
end
def primary_key(name)
- return unless column = self[name]
- column.type = native[:primary_key]
- self
+ column(name, native[:primary_key])
end
def [](name)
@@ -529,7 +526,7 @@ module ActiveRecord
def column(name, type, options = {})
column = self[name] || ColumnDefinition.new(@base, name, type)
- column.limit = options[:limit] || native[type.to_sym][:limit]
+ column.limit = options[:limit] || native[type.to_sym][:limit] if options[:limit] or native[type.to_sym]
column.default = options[:default]
@columns << column unless @columns.include? column
self
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index d5081e5335..60bdf90bf4 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -39,6 +39,17 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
end
+
+ def test_create_table_adds_id
+ Person.connection.create_table :testings do |t|
+ t.column :foo, :string
+ end
+
+ assert_equal %w(foo id),
+ Person.connection.columns(:testings).map { |c| c.name }.sort
+ ensure
+ Person.connection.drop_table :testings rescue nil
+ end
def test_native_types
Person.delete_all
@@ -198,4 +209,4 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_equal "hello world", Reminder.find(:first).content
end
end
-end \ No newline at end of file
+end