mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
95456eb4ef
commit
92fb0815ed
1 changed files with 10 additions and 6 deletions
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue