brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

Non-contiguous position column #365

Closed DanielHeath closed 4 years ago

DanielHeath commented 4 years ago

My position column has gotten into a state where it contains (eg) 1, 2, 6, 7 instead of 1,2,3,4.

I am not 100% whether this still happens, but it definitely has in the past; many users may have instances of this sitting around from back then.

When it's in this state, it's unclear what create!(position: 4) should do - specifically, should the new record be the fourth item in the list, or the third.

Personally I think it should be fourth, but I can see an argument for either. Before I take another look at https://github.com/brendon/acts_as_list/pull/334 I'd like to be clear which is expected.

brendon commented 4 years ago

Hi @DanielHeath, good to hear from you again :)

I think all we're saying is that this item will have a position of 4. Depending on if the list starts at 0 or 1 that could mean it's positioned at 4th or 5th place. It also depends on if there are gaps ahead of it (as you mention).

We don't manipulate the position value as far as I remember, so it's literally setting a value rather than intended position in the list.

Hope that helps :D Let me know if I've got it wrong :)

DanielHeath commented 4 years ago

Makes sense. For my use, I coalesce the list positions into a contiguous run at the end of each update, which keeps them sorted (that's roughly what my earlier PR was about, though it also removed an n+1 query).