reliese / laravel

Reliese Laravel Model Generator
MIT License
1.49k stars 316 forks source link

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

Open finiteinfinity opened 4 months ago

finiteinfinity commented 4 months ago

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.