Add a required option to the model generator#16062
Conversation
|
/cc @dhh |
|
We need to update the migration guides with this option. |
This should be done for any |
|
@egilburg That's a conversation that's still being had, no decision has been made one way or the other yet. |
|
For the record, I'm with @egilburg: whether we generate FKs at all will presumably be a generator config option (regardless of its chosen default), but I believe that choice is unrelated to whether the value is required. |
|
I'm 👍 on FKs all the time as well. It sounds like that's the way most are leaning, I'll pull that out to a separate PR. |
|
Looks good to me, but let's standardize on: |
|
@dhh That used to be the only splitter. The issue is using |
|
Ah. Bummer. Okay, then let's use for only if that works.
|
Syntax was chosen to follow the passing of multiple options to decimal/numeric types. Curly braces, and allowing any of `,`, `.`, or `-` to be used as a separator to avoid the need for shell quoting. (I'm intending to expand this to all columns, but that's another PR. The `required` option will cause 2 things to change. `required: true` will be added to the association. `null: false` will be added to the column in the migration.
|
This has been updated. |
Add a `required` option to the model generator
|
@sgrif @rafaelfranca Did the migration docs get updated for this yet? |
Related to this PR rails#16062 [ci skip]
Syntax was chosen to follow the passing of multiple options to
decimal/numeric types. Curly braces, and allowing any of
,,., or-to be used as a separator to avoid the need for shell quoting. (I'mintending to expand this to all columns, but that's another PR.
The
requiredoption will cause 3 things to change.required: truewill be added to the association.
null: falsewill be added to thecolumn in the migration.
add_foreign_key :table, :foreign_tablewillbe added if the association is not polymorphic.
Examples:
rails g model Account supplier:references{required}rails g model Account "supplier:references{required,polymorphic}"rails g model Account supplier:references{polymorphic-required}rails g model Account supplier:references{polymorphic.required}