lib/ridgepole/ext/schema_dumper.rb in ridgepole-1.2.1 vs lib/ridgepole/ext/schema_dumper.rb in ridgepole-2.0.0.beta
- old
+ new
@@ -28,11 +28,11 @@
parts = [
"add_foreign_key #{remove_prefix_and_suffix(foreign_key.from_table).inspect}",
remove_prefix_and_suffix(foreign_key.to_table).inspect
]
- parts << "column: #{foreign_key.column.inspect}" if foreign_key.column != @connection.foreign_key_column_for(foreign_key.to_table)
+ parts << "column: #{foreign_key.column.inspect}" if foreign_key.column != foreign_key_column_for(foreign_key)
parts << "primary_key: #{foreign_key.primary_key.inspect}" if foreign_key.custom_primary_key?
parts << "name: #{foreign_key.name.inspect}"
@@ -41,9 +41,19 @@
" #{parts.join(', ')}"
end
stream.puts add_foreign_key_statements.sort.join("\n")
+ end
+ end
+
+ private
+
+ def foreign_key_column_for(foreign_key)
+ if ActiveRecord.gem_version < Gem::Version.new('7.1.0')
+ @connection.foreign_key_column_for(foreign_key.to_table)
+ else
+ @connection.foreign_key_column_for(foreign_key.to_table, 'id')
end
end
end
end
end