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

Error when sorting on unique db index #101

Open
jacob418 opened this issue Aug 19, 2021 · 2 comments
Open

Error when sorting on unique db index #101

jacob418 opened this issue Aug 19, 2021 · 2 comments

Comments

@jacob418
Copy link

In my Project I have a unique index on the order column. When reordering the entries I receive a 'duplicate key entry' error for the order column. While investigating the code I noticed that the reordering is not encapsulated within a db-transaction.

I understand that in some cases one might not want to use a transaction but in general I would really like to have the ability to decide weather to use a transaction or not. Also a transaction would solve the duplicate key error:

  1. Start transaction
  2. Move the entry to the end (max possible sorting value)
  3. Reorder the other entries if needed
  4. Assign the now free order value to the entry from (2)
  5. Commit transaction

Using a transaction will prevent users from seeing an incorrect ordering in step (2)

@Tarpsvo
Copy link
Collaborator

Tarpsvo commented Oct 1, 2021

Transaction didn't seem to help, I wrapped the call in a transaction but it still throws the same error.

See this issue:
spatie/eloquent-sortable#44

@jacob418
Copy link
Author

I will try to have a look into this and maybe create a PR on the weekend.

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

No branches or pull requests

2 participants