Laravel 8:在将模型序列化到排队的作业时使用noRelations方法吗?

问题描述

我一直在阅读Laravel文档。在那里有明确的记载

If your queued job accepts an Eloquent model in its constructor,only the identifier for the model will be serialized onto the queue. When the job is actually handled,the queue system will automatically re-retrieve the full model instance and its loaded relationships from the database.

但是在“处理关系”部分中再次提到了

Because loaded relationships also get serialized,the serialized job string can become quite large. To prevent relations from being serialized,you can call the withoutRelations method on the model when setting a property value. This method will return an instance of the model with no loaded relationships

具有以下代码

/**
* Create a new job instance.
*
* @param  \App\Models\podcast  $podcast
* @return void
*/
public function __construct(podcast $podcast)
{
    $this->podcast = $podcast->withoutRelations();
}

此示例及其支持的段落矛盾,因为在第一段中明确提到如果模型在构造函数中传递,则仅模型的标识符将不相关地进行序列化。实际处理作业后,将检索完整模型及其关系。而在此示例中,我们显式调用norelations(),根据第一段,它是多余的,也没有具体说明第二段中的观点。

有人可以解释一下吗? 感谢您的答复和帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)