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

Eager loading target relationship on ActionEvent for a non soft-deleted model throws an exception #5754

Closed
marcmalha opened this issue Jul 27, 2023 · 3 comments
Assignees
Labels
bug Verified bug by the Nova team

Comments

@marcmalha
Copy link

marcmalha commented Jul 27, 2023

  • Laravel Version: 10.9.0
  • Nova Version: 4.23.0
  • PHP Version: 8.1.17
  • Database Driver & Version: psql (PostgreSQL) 14.7 (Ubuntu 14.7-1.pgdg22.04+1)
  • Operating System and Version: ubuntu:22.04 docker image
  • Browser type and version: Chrome 114.0.5735.198
  • Reproduction Repository: https://github.com/###/###

Description:

The issue is related to the target(): morphTo relationship on the ActionEvent object.
The relationship implementation assumes that the target model has a SoftDeletes trait, which in some cases it doesn't.
Trying to eager load a model that doesn't use the SoftDeletes trait will throw a BadMethodCallException with the following error message: Call to undefined method Illuminate\Database\Eloquent\Builder::withTrashed().

Detailed steps to reproduce the issue on a fresh Nova installation:

  • Run an action on a resource whose model is not soft deleted
  • Run a the following select query in a tinker session:
    ActionEvent::with('target')->where('actionable_type', (new NonSoftDeletedModel)->getMorphClass())->get()
@crynobone
Copy link
Member

Based on my test this seems to be an issue from the Framework especially Illuminate\Database\Eloquent\Relations\MorphTo::replayMacros():

[2023-07-27 23:54:32] local.ERROR: Call to undefined method Illuminate\Database\Eloquent\Builder::withTrashed() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method Illuminate\\Database\\Eloquent\\Builder::withTrashed() at /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:71)
[stacktrace]
#0 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(36): Illuminate\\Database\\Eloquent\\Builder::throwBadMethodCallException('withTrashed')
#1 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1660): Illuminate\\Database\\Eloquent\\Builder->forwardCallTo(Object(Illuminate\\Database\\Query\\Builder), 'withTrashed', Array)
#2 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php(362): Illuminate\\Database\\Eloquent\\Builder->__call('withTrashed', Array)
#3 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php(139): Illuminate\\Database\\Eloquent\\Relations\\MorphTo->replayMacros(Object(Illuminate\\Database\\Eloquent\\Builder))
#4 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php(121): Illuminate\\Database\\Eloquent\\Relations\\MorphTo->getResultsByType('App\\\\Models\\\\User')
#5 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(673): Illuminate\\Database\\Eloquent\\Relations\\MorphTo->getEager()
#6 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(642): Illuminate\\Database\\Eloquent\\Builder->eagerLoadRelation(Array, 'target', Object(Closure))
#7 /laravel/nova-dusk-suite/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(610): Illuminate\\Database\\Eloquent\\Builder->eagerLoadRelations(Array)
#8 /laravel/nova-dusk-suite/routes/web.php(24): Illuminate\\Database\\Eloquent\\Builder->get()

@crynobone crynobone added pending Issues that are pending triage bug Verified bug by the Nova team and removed pending Issues that are pending triage labels Jul 28, 2023
@crynobone crynobone self-assigned this Jul 28, 2023
@crynobone
Copy link
Member

Nevermind, this is under issue with Nova source code.

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

2 participants