-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
required
option will cause 3 things to change.required: true
will be added to the association.
null: false
will be added to thecolumn in the migration.
add_foreign_key :table, :foreign_table
willbe 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}