Detach before attach to prevent uniqueness constraint conflicts#724
Merged
taylorotwell merged 1 commit intoMar 27, 2013
Merged
Detach before attach to prevent uniqueness constraint conflicts#724taylorotwell merged 1 commit into
taylorotwell merged 1 commit into
Conversation
Example: You have a uniqueness constraint on id and position on the pivot table. You have a list of items and each items has a position in the list hence the position field on the pivot. You would like to remove one item from the bottom of the list and then add another one in it's place. You do this in a form, and get back a json object that has the new desired list of items. You would now like to sync this json object up with the db so you use sync(). Now sync() will try to attach a new item with a position of 3, but that position already exists and an exception is thrown. By first detaching the old item in position 3 and then attaching the new one this conflict is removed. Signed-off-by: Andreas Heiberg <[email protected]>
taylorotwell
added a commit
that referenced
this pull request
Mar 27, 2013
…traint-conflicts Detach before attach to prevent uniqueness constraint conflicts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Example:
You have a uniqueness constraint on id and position on the pivot table. You have a list of items and each items has a position in the list hence the position field on the pivot.
You would like to remove one item from the bottom of the list and then add another one in it's place. You do this in a form, and get back a json object that has the new desired list of items. You would now like to sync this json object up with the db so you use sync(). Now sync() will try to attach a new item with a position of 3, but that position already exists and an exception is thrown.
By first detaching the old item in position 3 and then attaching the new one this conflict is removed.
Signed-off-by: Andreas Heiberg [email protected]