-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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 singular associations
#16056
Conversation
/cc @dhh |
Looks great to me 👍! |
Build failed? |
In addition to defining the association, a `required` association will also have its presence validated. Before: ```ruby belongs_to :account validates_presence_of :account ``` After: ```ruby belongs_to :account, required: true ``` This helps to draw a distinction between types of validations, since validations on associations are generally for data integrity purposes, and aren't usually set through form inputs.
Issue with mysql and the test cases I added, updated, should pass on this run. |
Add a `required` option to singular associations
❤️ |
Not sure this ever worked as expected see: rails/rails@0950d40 rails/rails#16056 for a bit of history
Not sure this ever worked as expected see: rails/rails@0950d40 rails/rails#16056 for a bit of history
@sgrif The documentation added by this PR says:
This sentence is still part of the current documentation. The way in which I interpret this is that:
However that is not the case. The extra query still takes place since this code is still running: if reflection.options[:required]
model.validates_presence_of reflection.name
end Can you help me understand if I'm missing something? |
In addition to defining the association, a
required
association willalso have its presence validated.
Before:
After:
This helps to draw a distinction between types of validations, since
validations on associations are generally for data integrity purposes,
and aren't usually set through form inputs.