aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-09-15 21:23:05 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-09-15 21:23:05 +0000
commit79202b37dc7566e8b8392a44c461a64469f79a77 (patch)
tree14f21cc3a9706a3c9dd3a6b7fc4c91d6977858aa
parent2fba012c018a7e29e5e0afa2ba6a6ea91b07b0a3 (diff)
downloadrails-79202b37dc7566e8b8392a44c461a64469f79a77.tar.gz
rails-79202b37dc7566e8b8392a44c461a64469f79a77.tar.bz2
rails-79202b37dc7566e8b8392a44c461a64469f79a77.zip
Fixed that altering join tables in migrations would fail w/ sqlite3 #7453 [TimoMihaljov/brandon]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7484 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb3
-rw-r--r--activerecord/test/copy_table_test_sqlite.rb4
3 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 81cf47529e..81ca1da94f 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that altering join tables in migrations would fail w/ sqlite3 #7453 [TimoMihaljov/brandon]
+
* Fix association writer with :dependent => :nullify. #7314 [Jonathan Viney]
* OpenBase: update for new lib and latest Rails. Support migrations. #8748 [dcsesq]
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 963d4b92bd..f985bd9615 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -285,6 +285,7 @@ module ActiveRecord
end
def copy_table(from, to, options = {}) #:nodoc:
+ options = options.merge(:id => !columns(from).detect{|c| c.name == 'id'}.nil?)
create_table(to, options) do |@definition|
columns(from).each do |column|
column_name = options[:rename] ?
@@ -296,7 +297,7 @@ module ActiveRecord
:limit => column.limit, :default => column.default,
:null => column.null)
end
- @definition.primary_key(primary_key(from))
+ @definition.primary_key(primary_key(from)) if primary_key(from)
yield @definition if block_given?
end
diff --git a/activerecord/test/copy_table_test_sqlite.rb b/activerecord/test/copy_table_test_sqlite.rb
index 6da041522f..a25780e6be 100644
--- a/activerecord/test/copy_table_test_sqlite.rb
+++ b/activerecord/test/copy_table_test_sqlite.rb
@@ -42,6 +42,10 @@ class CopyTableTest < Test::Unit::TestCase
end
end
+ def test_copy_table_without_primary_key
+ test_copy_table('developers_projects', 'programmers_projects')
+ end
+
protected
def copy_table(from, to, options = {})
@connection.copy_table(from, to, {:temporary => true}.merge(options))