Add a required option to singular associations#16056
Merged
dhh merged 1 commit intorails:masterfrom Jul 5, 2014
Merged
Conversation
Contributor
Author
|
/cc @dhh |
Member
|
Looks great to me 👍! |
Member
|
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.
Contributor
Author
|
Issue with mysql and the test cases I added, updated, should pass on this run. |
dhh
added a commit
that referenced
this pull request
Jul 5, 2014
Add a `required` option to singular associations
sgrif
added a commit
that referenced
this pull request
Jul 5, 2014
Member
|
❤️ |
huoxito
added a commit
to spree/spree
that referenced
this pull request
Oct 23, 2014
Not sure this ever worked as expected see: rails/rails@0950d40 rails/rails#16056 for a bit of history
JDutil
pushed a commit
to JDutil/spree
that referenced
this pull request
Mar 31, 2015
Not sure this ever worked as expected see: rails/rails@0950d40 rails/rails#16056 for a bit of history
Member
|
@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
endCan you help me understand if I'm missing something? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In addition to defining the association, a
requiredassociation 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.