aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorTee Parham <tee@neighborland.com>2014-09-06 11:52:26 -0600
committerTee Parham <tee@neighborland.com>2014-09-07 16:52:01 -0600
commit92fb0815ed3cb92ae18ce8c9cf401ee1b74a971d (patch)
treef3ad23b21478eddd332ac6197dfa69faf4a78c60 /activerecord
parent95456eb4efd5bbfb6ff1cca429b9b146708f4f18 (diff)
downloadrails-92fb0815ed3cb92ae18ce8c9cf401ee1b74a971d.tar.gz
rails-92fb0815ed3cb92ae18ce8c9cf401ee1b74a971d.tar.bz2
rails-92fb0815ed3cb92ae18ce8c9cf401ee1b74a971d.zip
Fix warnings for undefined local variable
* Add private method primary_key_for, which more clearly shows that the expected return value is nil when a primary key is not found.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 4888907f51..b560c58a66 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -105,18 +105,22 @@ HEADER
end
end
+ def primary_key_for(table)
+ if @connection.respond_to?(:pk_and_sequence_for)
+ pk, _ = @connection.pk_and_sequence_for(table)
+ return pk if pk
+ end
+ return @connection.primary_key(table) if @connection.respond_to?(:primary_key)
+ nil
+ end
+
def table(table, stream)
columns = @connection.columns(table)
begin
tbl = StringIO.new
# first dump primary key column
- if @connection.respond_to?(:pk_and_sequence_for)
- pk, _ = @connection.pk_and_sequence_for(table)
- end
- if !pk && @connection.respond_to?(:primary_key)
- pk = @connection.primary_key(table)
- end
+ pk = primary_key_for(table)
tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}"
pkcol = columns.detect { |c| c.name == pk }