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

syncWithoutDetaching inserts duplicate entries when sending concurrent requests #21639

Closed
ketysek opened this issue Oct 12, 2017 · 6 comments

Comments

@ketysek
Copy link

commented Oct 12, 2017

  • Laravel Version: 5.4.36
  • PHP Version: 5.6.30
  • Database Driver & Version: MySQL 5.7

Description:

Assume tables and many to many relationship between them.
When I send concurrent requests (at same time), syncWithoutDetaching doesn't work correctly and inserts new rows in pivot table. This broke my application, because I expected unique pairs of foreign keys in my pivot table.

Steps To Reproduce:

  • create 2 tables with many to many relationship between; my pivot table has an additional integer column called value
  • send some number of concurrent request on method where syncWithoutDetaching is applied
@sisve

This comment has been minimized.

Copy link
Contributor

commented Oct 13, 2017

Well, concurrency requires some kind of locking system to ensure that you're the only one doing the change. Are you using any locking? Perhaps database transactions with a high transaction level?

@themsaid

This comment has been minimized.

Copy link
Member

commented Oct 13, 2017

This should be handled in your app, check Laravel 5.5 Locking feature.

@themsaid themsaid closed this Oct 13, 2017

@fede91it

This comment has been minimized.

Copy link

commented Apr 1, 2019

This problem is still present in my end

@themsaid

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

@fede91it check my reply above :)

@devcircus

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2019

This is an issue you'll need to handle in your app. You may get some assistance from the locking feature of Laravel. There are also some packages available that may help.

@fede91it

This comment has been minimized.

Copy link

commented Apr 1, 2019

Do you suggest someone in particolar? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.