Order is broken when position changed to nil
molfar opened this issue · 3 comments
molfar commented
I have ordered set of records:
<Item id=1 position=0>
<Item id=2 position=1>
<Item id=3 position=2>
When I set position to nil value
Item.find(2).update position: nil
Then I get broken order:
<Item id=1 position=0>
<Item id=3 position=2>
<Item id=2 position=nil>
But expected result is:
<Item id=1 position=0>
<Item id=3 position=1>
<Item id=2 position=nil>
molfar commented
@brendon ok, but is there any explicit way? I update the record with params coming from user form.
item = Item.find params[:id]
item.update params[:item] # position param included here
When user set position to blank value, it is expected item to be removed from list. Or we should manually check if params[:position] was blank, then remove_from_list?