Skip to content

Relationships that soft-delete should have nullable property type-hints #290

@finiteinfinity

Description

@finiteinfinity

Given these tables

CREATE TABLE users
(
    id        BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    managerId BIGINT UNSIGNED NOT NULL,
    deletedAt DATETIME(6)     NULL,
    CONSTRAINT users_managerId_foreign
        FOREIGN KEY (managerId) REFERENCES users (id)
)

we get the following type-hints for the User model:

@property User $manager

however, when the related user record is (soft) deleted, we no longer get access to the data through the property thanks to the SoftDeleting scope Laravel provides.

The suggestion here is to add a new config value (to preserve BC) which generated these properties as nullable to reflect the fact that they may actually contain a null value.

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