aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-06-30 02:39:36 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-07-02 15:21:02 +0900
commitcf09d5bd63a6c886d0417163de2e966669c52809 (patch)
tree3284be5e84bb7d9a02d43ae975aebf0dd9e8b3f8 /activerecord/lib/active_record/attribute_methods
parent8fb699571486ad752741672e6fec1132026d3dfb (diff)
downloadrails-cf09d5bd63a6c886d0417163de2e966669c52809.tar.gz
rails-cf09d5bd63a6c886d0417163de2e966669c52809.tar.bz2
rails-cf09d5bd63a6c886d0417163de2e966669c52809.zip
Move the warning about composite primary key to `AttributeMethods::PrimaryKey`
Actually schema dumper/creation supports composite primary key (#21614). Therefore it should not show the warning about composite primary key in connection adapter. This change moves the warning to `AttributeMethods::PrimaryKey` and suppress the warning for habtm join table. Fixes #25388.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index 0d5cb8b37c..d28edfb003 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -95,7 +95,8 @@ module ActiveRecord
base_name.foreign_key
else
if ActiveRecord::Base != self && table_exists?
- connection.schema_cache.primary_keys(table_name)
+ pk = connection.schema_cache.primary_keys(table_name)
+ suppress_composite_primary_key(pk)
else
'id'
end
@@ -122,6 +123,18 @@ module ActiveRecord
@quoted_primary_key = nil
@attributes_builder = nil
end
+
+ private
+
+ def suppress_composite_primary_key(pk)
+ return pk unless pk.is_a?(Array)
+
+ warn <<-WARNING.strip_heredoc
+ WARNING: Active Record does not support composite primary key.
+
+ #{table_name} has composite primary key. Composite primary key is ignored.
+ WARNING
+ end
end
end
end