如何解决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 举报,一经查实,本站将立刻删除。