Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.04k stars 885 forks source link

Streamline the eager load of relationships in crud objects #5563

Closed pxpm closed 4 weeks ago

pxpm commented 1 month ago

WHY

BEFORE - What was wrong? What was happening before this PR?

We could only eager load relationships in in columns crud object type and that prevented us from eager loading the relationships for fields in the update form.

AFTER - What is happening after this PR?

We can eager load relationships for multiple object types (eg: columns and fields), and by consequence we can now eager load relationships on the update form.

HOW

How did you achieve that, in technical terms?

Generalizing the eager load method and creating some additional helper methods we can now eager load columns and fields.

Added settings to disable this behavior on the relevant operations, for list operation it eager loads by default to keep previous behavior, and in update is disabled by default to avoid potentially breaking changes. We have the opportunity to enable it by default in the next version for update.

Is it a breaking change?

I don't think so, no.

How can we test the before & after?

Enable the feature in config/backpack/opeations/update.php. Create a monster with a few relationships, like 3 or 4 belongs to many entries. See the number of queries in main vs this branch.

tabacitu commented 4 weeks ago

I absolutely LOVE this. Very nicely implemented, Pedro! Cleans up things quite a bit, for something that was inconsistent. I love it! Haven't tested it, but given the code a good look - doesn't seem like it would cause problems to me. I noticed you kept the same behaviour as before (the defaults).

Nice!