Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve related save #2599

Merged
merged 5 commits into from
Oct 14, 2024
Merged

Improve related save #2599

merged 5 commits into from
Oct 14, 2024

Conversation

Tofandel
Copy link
Contributor

@Tofandel Tofandel commented Jun 5, 2024

A quick PR to improve saveRelated to work with models, I wanted to use it and according to the phpdoc it accepts an array of Twill model, but this is not the case (it only accepts an array with id and endpointType)

This PR allows the method to accept models as well and improves the performance by using only one where instead of 3 which would iterate 3 times over the collection

I also added $item->unsetRelation('related') in loadRelated, otherwise there is a circular reference in the model relation (model -> pivot -> related -> model ...) which causes an infinite loop when using model->toArray()

$firstMatchKey = $itemsToProcess
->where('related_id', $item['id'])
->where('related_type', $item['endpointType'])
->where('browser_name', $browserName)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already taken care of in line 71

@ifox ifox merged commit 669bed0 into area17:3.x Oct 14, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants