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

Model strict mode not work #72

Open
adeiming opened this issue Apr 19, 2024 · 3 comments
Open

Model strict mode not work #72

adeiming opened this issue Apr 19, 2024 · 3 comments

Comments

@adeiming
Copy link

with

public function boot(): void
{        
    Model::shouldBeStrict(true);
}

in AppServiceProvider not work properly v4.4

@michaeldyrynda
Copy link
Owner

Can you provide more detail about what isn’t working? Errors, expected behaviour, etc.

Minimum reproduction repo of the error would be helpful.

@adeiming
Copy link
Author

Model

class Zone extends Model
{
    use SoftDeletes, CascadeSoftDeletes;

    protected $cascadeDeletes = ['records'];

    public function records(): HasMany
    {
        return $this->hasMany(ResourceRecord::class);
    }
}

Controller

public function delete(Request $request, string $id)
{
    Zone::destroy($id);
}

Result:

Attempted to lazy load [zone] on model [App\Models\ResourceRecord] but lazy loading is disabled.

An error will occur if the data record is more than 1

@guictx
Copy link

guictx commented Sep 19, 2024

I confirm this issue in Laravel 11 with the latest version of this package.

It happens when a model with more than 1 dependent models in a HasMany relationship is deleted.

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

3 participants