brendon / acts_as_list

An ActiveRecord plugin for managing lists.

Home Page:http://brendon.github.io/acts_as_list/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-contiguous position column

DanielHeath opened this issue · comments

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 #334 I'd like to be clear which is expected.

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 :)

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).