简体   繁体   English

在 OctoberCMS 中急切加载关系数据

[英]Eager Loading of Relation data in OctoberCMS

I am using a form that has a relation field inside.我正在使用一个内部有一个关系字段的表单。 Although this is fine when few items are in the relation it gets quite slow when there are a lot.虽然当关系中的项目很少时这很好,但当有很多项目时会变得很慢。 I wish to eager load some of the relationships to improve response times but I find it hard to find where I can access the query builder before it is run.我希望急切地加载一些关系以缩短响应时间,但我发现在运行之前很难找到可以访问查询构建器的位置。

If I were using a standard list view I would go about doing this by extending the list query as below:如果我使用的是标准列表视图,我会 go 通过扩展列表查询来做到这一点,如下所示:

public function listExtendQuery($query)
{
    $query->with(['photos'])
}

But I have no idea how I can perform the exact same thing when loading the list using the relation widget.但是我不知道在使用关系小部件加载列表时如何执行完全相同的操作。 I have gone through the documentation multiple times but I did not manage to get this working.我已经多次阅读文档,但我没有设法让它工作。

Can anyone assist on this?有人可以帮忙吗?

Would you believe if we told you that formExtendQuery method is a thing?如果我们告诉你formExtendQuery 方法是一个东西,你会相信吗? :) :)

public function formExtendQuery($query)
{
    $query->with(['photos']);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM