aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb4
-rw-r--r--activerecord/test/migration_test.rb8
3 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 773e4ce90e..d3b5a38ec8 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu]
+
* Fixtures: removed support for the ancient pre-YAML file format. #10736 [John Barnette]
* More thoroughly quote table names. #10698 [dimdenis, lotswholetime, Jeremy Kemper]
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 79b66be8ef..8b2f3ad5d4 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -453,9 +453,7 @@ module ActiveRecord
polymorphic = options.delete(:polymorphic)
args.each do |col|
column("#{col}_id", :integer, options)
- unless polymorphic.nil?
- column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : {})
- end
+ column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) unless polymorphic.nil?
end
end
alias :belongs_to :references
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index 3b74604c44..f2683f3aef 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -925,6 +925,14 @@ if ActiveRecord::Base.connection.supports_migrations?
end
end
+ def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
+ with_new_table do |t|
+ t.expects(:column).with('taggable_type', :string, {:null => false})
+ t.expects(:column).with('taggable_id', :integer, {:null => false})
+ t.references :taggable, :polymorphic => true, :null => false
+ end
+ end
+
def test_belongs_to_works_like_references
with_new_table do |t|
t.expects(:column).with('customer_id', :integer, {})