Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Add a `required` option to singular associations #16056
In addition to defining the association, a
belongs_to :account validates_presence_of :account
belongs_to :account, required: true
This helps to draw a distinction between types of validations, since
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.
@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?