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

[11.x] Don't touch BelongsTo relationship when it doesn't exist #52407

Conversation

patrickomeara
Copy link
Contributor

Currently, MorphTo and BelongsToMany check for relation existence before sending the update query to the database.

This adds that check to the BelongsTo relationship.

I found this when trawling through query logs. Nullable belongs to relationship were producing a lot of unnecessary update queries

update
  `table`
set
  `table`.`updated_at` = '2024-08-07 02:46:18'
where
  `table`.`id` is null

Additionally, getParentKey() can be used to find the child foreign key value.

Currently, MorphTo and BelongsToMany check for relation existence before sending the update query to the database.

This adds that check to the BelongsTo relationship.

`getParentKey()` can be used to find the child foreign key value
@patrickomeara patrickomeara force-pushed the dont-touch-belongs-to-when-relation-does-not-exist branch from dbfd1c7 to 37b15c1 Compare August 7, 2024 02:49
@taylorotwell taylorotwell merged commit dd649c6 into laravel:11.x Aug 7, 2024
29 checks passed
RazinTeqB added a commit to RazinTeqB/framework that referenced this pull request Aug 28, 2024
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