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

Issue with ordering of items when called through a parent.create #94

Open
raffij opened this issue Mar 18, 2015 · 2 comments
Open

Issue with ordering of items when called through a parent.create #94

raffij opened this issue Mar 18, 2015 · 2 comments

Comments

@raffij
Copy link

raffij commented Mar 18, 2015

Example:

List -> ListItem -> Item

When creating a new List with item_ids the ordering of some elements will not be correct.

30.times { |t| Item.create(name: "Item #{t}") }

List.create(name: "List 1", item_ids: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])

On the initial create the ordering is set correctly, however there's a secondary save which doesn't update the ordering of all the items which had an initial order of MAX_ORDER_NO=8388607.

Expected output:

ListItem.ordered.map(&:id)
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]

Actual output:

ListItem.ordered.map(&:id)
[1, 24, 25, 26, 27, 28, 29, 30, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]

Sample test case:

https://github.com/raffij/ranked-model-test

@mixonic
Copy link
Contributor

mixonic commented Mar 18, 2015

@raffij seems likes a possible bug. Changing the order is a viable work around:

list = List.create(name: "List 1")
30.times { |t| Item.create(name: "Item #{t}", list: list) }

And would avoid the second update to every item. This is just a work around though, it seems possible the issue is legit.

@raffij
Copy link
Author

raffij commented Mar 18, 2015

@mixonic agreed. That's going to be the current workaround, but wanted to let you know there was an issue.

The issue occurs because once the MAX_LIMIT is hit the subsequent changes are made directly in sql. Therefore the object position attribute doesn't get updated as no reload takes place.

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