Add a `required` option to singular associations #16056

Merged
merged 1 commit into from Jul 5, 2014

Conversation

Projects
None yet
3 participants
@sgrif
Member

sgrif commented Jul 4, 2014

In addition to defining the association, a required association will
also have its presence validated.

Before:

belongs_to :account
validates_presence_of :account

After:

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

This comment has been minimized.

Show comment
Hide comment
@sgrif

sgrif Jul 4, 2014

Member

/cc @dhh

Member

sgrif commented Jul 4, 2014

/cc @dhh

@dhh

This comment has been minimized.

Show comment
Hide comment
@dhh

dhh Jul 4, 2014

Member

Looks great to me 👍!

Member

dhh commented Jul 4, 2014

Looks great to me 👍!

@dhh

This comment has been minimized.

Show comment
Hide comment
@dhh

dhh Jul 4, 2014

Member

Build failed?

Member

dhh commented Jul 4, 2014

Build failed?

Add a `required` option to singular associations
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

This comment has been minimized.

Show comment
Hide comment
@sgrif

sgrif Jul 4, 2014

Member

Issue with mysql and the test cases I added, updated, should pass on this run.

Member

sgrif commented Jul 4, 2014

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

Merge pull request #16056 from sgrif/sg-required-associations
Add a `required` option to singular associations

@dhh dhh merged commit 3ac8118 into rails:master Jul 5, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

sgrif added a commit that referenced this pull request Jul 5, 2014

@sgrif sgrif deleted the sgrif:sg-required-associations branch Jul 5, 2014

@guilleiguaran

This comment has been minimized.

Show comment
Hide comment
@guilleiguaran

guilleiguaran Jul 17, 2014

Member

❤️

Member

guilleiguaran commented Jul 17, 2014

❤️

huoxito added a commit to spree/spree that referenced this pull request Oct 23, 2014

Drop validate presence: true on PromotionRule
Not sure this ever worked as expected see:

rails/rails@0950d40
rails/rails#16056

for a bit of history

JDutil added a commit to JDutil/spree that referenced this pull request Mar 31, 2015

Drop validate presence: true on PromotionRule
Not sure this ever worked as expected see:

rails/rails@0950d40
rails/rails#16056

for a bit of history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment