Queued Actions do not serialize models properly. #3375
Answered
by
crynobone
rakishii13
asked this question in
Q&A
-
Description: Models do not properly serialize in a Queued Action that is then calling a Queued Job.If an Action is queued that is then dispatching to a queued job through the Detailed steps to reproduce the issue on a fresh Nova installation:
Just then dumping out the queries, you can see that there was no relations loaded for the job. |
Beta Was this translation helpful? Give feedback.
Answered by
crynobone
May 4, 2021
Replies: 1 comment
-
You should be able to do the following: namespace App;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
class QueuedJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public Collection $models;
/**
* Create a new job instance.
*
* @param \Illuminate\Support\Collection $models
* @return void
*/
public function __construct(Collection $models)
{
$this->models = $models;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->models->loadMissing('relations');
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
crynobone
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cursor()
to speed up populating actions for large resources.QueuedAction
,QueuedAction
will then have to query model (and relation) again, and thenQueuedJob
will also need to re-query model (and relations). This is highly inefficient.You should be able to do the following: