E
E
Ernest Faizullin2019-06-20 12:25:52
Laravel
Ernest Faizullin, 2019-06-20 12:25:52

Why RelationNotFoundException when executing a Job in a queue?

Hello. There is a many-to-many relationship with a table respondent_answer(laravel 5.3)

class Respondent {
    // ...
    public function answers()
    {
        return $this->belongsToMany(Answer::class);
    }
}

class Answer {
    // ...
    public function respondents()
    {
        return $this->belongsToMany(Respondent::class);
    }
}

there is also one Jobthat is executed in the queue
class AnalyzeRespondentAnswersJob implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    // ...

    public function handle()
    {
        $respondent = $this->event->respondent->fresh(['answers']); // тут падает ошибка RelationNotFoundException
        // ...
    }
}

Error text:
production.ERROR: exception 'Illuminate\Database\Eloquent\RelationNotFoundException' with message 'Call to undefined relationship [answers] on model [App\Models\Respondent].'

Please note that the connection answersexists, and in tinker it works correctly. Also on another server exactly the same code works without errors.
Here's what I tried to do to get rid of the error:
composer dump
php artisan cache:clear
php artisan clear-compiled
php artisan optimize
php artisan queue:restart
service nginx restart
service php-fpm restart
but the error continues to fall when the Job is executed. What did I miss?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Ernest Faizullin, 2019-06-24
@erniesto77

the problem was in php-fpm caching https://friendhosting.net/blog/kyeshirovanie-php-f...

A
Alex Wells, 2019-06-21
@Alex_Wells

Set up xdebug for yourself, put a breakpoint in the job and see what comes there. With some combination of keys (as on Windows xs) you can open the "console" - pull yourself the necessary relations / methods and look.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question