Skip to content
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

Reworking belongs_to precense validations #57

Open
urkle opened this issue Dec 31, 2017 · 0 comments
Open

Reworking belongs_to precense validations #57

urkle opened this issue Dec 31, 2017 · 0 comments

Comments

@urkle
Copy link
Member

urkle commented Dec 31, 2017

Currently a validation for a column like this

      t.belongs_to :organization, {
          null: false,
          foreign_key: {on_update: :restrict, on_delete: :cascade},
          index: true
      }

is being generated as this

[schema_validations] Project.validates_presence_of :organization

It should instead be created as this

[schema_validations] Project.validates_presence_of :organization_id

As we have an FK constraint at the DB level, thus that will enforce that a proper value will be created. This will save having to do an extra hit the DB (and loading the entire model) to validate that the org_id is a valid one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant