brendon/positioning

Conditional set positioning?

jwcooper opened this issue · 5 comments

First, thanks for the library, looks pretty interesting compared to acts_as_list (how I found it).

Is it possible to create a position that is only set if a condition is true?

Something like the following:

positioned on: :category, column: :category_position, if: :enabled?

This would be used in the situation where you only want a position on certain records.

If I use something like:

positioned on: [:category, :enabled]

That does work well, but it also creates positions for categories that are not enabled.

Hi @jwcooper, great to see you found this gem :D

The current assumption is that every item in a table sits within a scope of some kind (or a global scope). Apart from perhaps a bit of database overhead, there's nothing wrong with ignoring the 'not enabled' scope in terms of positioning. You aren't forced to order non-enabled items (though they will have an innate order). If you enable an item and don't explicitly set its position, it'll go to the end of the list.

I think adding conditional membership criteria will complicate things quite a bit, and in the end I'm still going to have to bring an item in and out scope the same way (except I won't have to close or open a gap when an item comes in and out of scope). What do you think?

Hey thanks for the detailed response.

Yea, this all makes sense. It's easy enough to just ignore those records that don't pertain to the scope of the positioning column. I tested things further and this should work well for my requirements. The tiny extra db overhead is certainly fine in this situation.

Thanks @jwcooper, that's great to hear. Please keep me updated on your experiences with the gem. In particular I'm keen to know if you have any issues with the Advisory Lock technique used to keep list actions sequential.

@jwcooper What solution solved your problem?

@jwcooper What solution solved your problem?

I basically used my second example from my initial question. No conditional, and querying for the records I actually need. They'll still be properly ordered.