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

Use model's qualified key name for update queries #175

Merged
merged 1 commit into from
May 2, 2024

Conversation

JeremyDunn
Copy link
Contributor

This fixes an issue where if your model's custom sort query joins on a related table, updates can result in aColumn '{key}' in where clause is ambiguous error.

For example:

update `order_items`
inner join `orders` on `order_items`.`order_id` = `orders`.`id`
set
  `sort_order` = `sort_order` - 1,
  `order_items`.`updated_at` = '2024-04-28 09:52:43'
where
  `orders`.`status` in ('processing', 'on-hold')
  and `queue_priority_group` = 'high'
  and `id` != 230
  and `sort_order` > 11

Using the model's qualified key name prevents this.

@freekmurze freekmurze merged commit fb8a5d0 into spatie:main May 2, 2024
17 checks passed
@freekmurze
Copy link
Member

Thank you!

@JeremyDunn JeremyDunn deleted the qualified-key-name branch May 2, 2024 12:10
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