How to generate model and migration with associations


#1

Hello, I’ve tried to generate a model and migration with associations with the following command:

jets generate model post title:string body:text site:references

But it fails with:

      invoke  active_record
Traceback (most recent call last):
        58: from /Users/me/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `<main>'
        57: from /Users/me/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `eval'
        56: from /Users/me/.rvm/gems/ruby-2.6.5/bin/jets:23:in `<main>'
        55: from /Users/me/.rvm/gems/ruby-2.6.5/bin/jets:23:in `load'
        54: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/exe/jets:14:in `<top (required)>'
        53: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/lib/jets/cli.rb:5:in `start'
        52: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/lib/jets/cli.rb:28:in `start'
        51: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/lib/jets/commands/base.rb:27:in `perform'
        50: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/lib/jets/commands/base.rb:38:in `dispatch'
        49: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
        48: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        47: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        46: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/lib/jets/commands/main.rb:103:in `generate'
        45: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/lib/jets/generator.rb:5:in `invoke'
        44: from /Users/me/.rvm/gems/ruby-2.6.5/gems/jets-2.3.1/lib/jets/generator.rb:82:in `run'
        43: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators.rb:276:in `invoke'
        42: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
        41: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
        40: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
        39: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
        38: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
        37: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
        36: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        35: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        34: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/group.rb:134:in `_invoke_from_option_orm'
        33: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/group.rb:266:in `_invoke_for_class_method'
        32: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/shell.rb:68:in `with_padding'
        31: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/group.rb:277:in `block in _invoke_for_class_method'
        30: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:115:in `invoke'
        29: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
        28: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
        27: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
        26: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
        25: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
        24: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        23: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        22: from /Users/me/.rvm/gems/ruby-2.6.5/gems/activerecord-6.0.0/lib/rails/generators/active_record/model/model_generator.rb:23:in `create_migration_file'
        21: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/migration.rb:65:in `migration_template'
        20: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/migration.rb:36:in `create_migration'
        19: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/actions.rb:94:in `action'
        18: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/actions/create_file.rb:60:in `invoke!'
        17: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/actions/empty_directory.rb:117:in `invoke_with_conflict_check'
        16: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/actions/create_file.rb:63:in `block in invoke!'
        15: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/actions/create_file.rb:63:in `open'
        14: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/actions/create_file.rb:63:in `block (2 levels) in invoke!'
        13: from /Users/me/.rvm/gems/ruby-2.6.5/gems/thor-0.20.3/lib/thor/actions/create_file.rb:53:in `render'
        12: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/migration.rb:67:in `block in migration_template'
        11: from /Users/me/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/erb.rb:901:in `result'
        10: from /Users/me/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/erb.rb:901:in `eval'
         9: from (erb):4:in `migration_template'
         8: from (erb):4:in `each'
         7: from (erb):10:in `block in migration_template'
         6: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/generated_attribute.rb:183:in `inject_options'
         5: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/generated_attribute.rb:183:in `tap'
         4: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/generated_attribute.rb:183:in `block in inject_options'
         3: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/generated_attribute.rb:191:in `options_for_migration'
         2: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/generated_attribute.rb:191:in `tap'
         1: from /Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/generated_attribute.rb:192:in `block in options_for_migration'
/Users/me/.rvm/gems/ruby-2.6.5/gems/railties-6.0.0/lib/rails/generators/generated_attribute.rb:147:in `required?': undefined method `application' for Rails:Module (NoMethodError)

Is this command not supported?

Thank you.


#2

Bummer. Works:

jets generate model post title:string body:text

Doesnt work:

jets generate model post title:string body:text site:references

So there’s something funny with site:references. Would just manually add what site:references does in the migration for now.