Suppose I have some objects, and I want the user to be able to reorder them in any way they wish, say, by dragging them around. So I’d have
- Cheese
- Muffins
- Milk
And then the user drags ‘milk’ to the top, making the new order
- Milk
- Cheese
- Muffins
Is there a best practice how to store the order of these objects in a database? The naive approach would probably be to just store a numerical value called ‘order’ for each object, but this seems like too much hassle to me, because you’d have to shuffle the order-values around most of the time.
The ‘naive’ approach you suggest is also the best practice!