Skip to content

Reworking belongs_to precense validations #57

@urkle

Description

@urkle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions