schema_to_scaffold
schema_to_scaffold copied to clipboard
undefined method `to_script' for nil:NilClass
Description
Hullo.
I'm seeing the error below when running scaffold
. It occurs when being run for single, or multiple tables, so it's similar to, but different from #14.
undefined method `to_script' for nil:NilClass
attributes_list = attributes.map(&:to_script).reject { |x| x.nil? || x.empty? }.join(' ') ^^^^
Table
#<SchemaToScaffold::Table:0x0000000101dcbb38 @name="competitions", @attributes=[#<SchemaToScaffold::Attribute:0x0000000101f208a8 @name="opta", @type="references">, #<SchemaToScaffold::Attribute:0x0000000101f20678 @name="perform", @type="references">, #<SchemaToScaffold::Attribute:0x0000000101f20498 @name="perform_code", @type="string">, #<SchemaToScaffold::Attribute:0x0000000101f202b8 @name="name", @type="string">, #<SchemaToScaffold::Attribute:0x0000000101f200d8 @name="created_at", @type="timestamptz">, #<SchemaToScaffold::Attribute:0x0000000101dcbd68 @name="updated_at", @type="timestamptz">, nil, nil]>
Cause
I've tracked the issue down to these two lines in my schema.rb
file:
t.unique_constraint ["opta_id"], name: "competitions_opta_id_key"
t.unique_constraint ["perform_id"], name: "competitions_perform_id_key"
Once I delete those I'm able to run scaffold
without issue.
Context
Ruby: 3.1.2 Rails: 7.1.2 OS: MacOS 12.6.3 Scaffold: 0.8.2
To clarify, I have to remove the unique_constraint
lines from schema.rb
completely. scaffold
will still try to read the attributes if they are commented out like this:
# t.unique_constraint ["opta_id"], name: "competitions_opta_id_key"
# t.unique_constraint ["perform_id"], name: "competitions_perform_id_key"