0

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:

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?

paishin
  • 258
  • 1
  • 5
  • 15

1 Answers1

0

Would you believe if we told you that formExtendQuery method is a thing? :)

public function formExtendQuery($query)
{
    $query->with(['photos']);
}
Eoler
  • 131
  • 2
  • 4
  • I actually would, cause I've already tried that :) It does not seem to have any effect on the relation field (not to be confused with database/model relationships). – paishin Jul 22 '20 at 13:11
  • Ah. Did you check with debug toolbar or some other way? There's also relationExtendViewWidget method with (parent) $model parameter, maybe it could be useful? – Eoler Jul 22 '20 at 17:22