0

Working on a simple todo app that allows the users to sort the tasks by hand. It's fairly simply to implement the model based on a LinkedList in Java.

Yet if I want to persist the sorted tasks in a relational database I would have to add a new column that provides an index by which I can sort the tasks.

The problem would be that every time a user changes the sorting (take for example that she puts the fourth task at the second position) I would have to update every task to fix the indexes in the database. That seems quite nasty to me. Is there a more elegant way to solve this problem?

TimKaechele
  • 510
  • 5
  • 12
  • It's just data. Put it in the database. You can use ordered indexes to help the dbms minimize effort. See answers at link above, *the first google hit of my first search* of 'stackoverflow sorted list sql'. – philipxy Dec 31 '15 at 20:19

2 Answers2

1

You should not put UI information in your business data. You should rather create ui_preferences table and store the information there. You then just have to get the information before querying your business data. You could also store this information in a cookie /session storage in your browser but maybe that doesn't fit your requirements

benjamin.d
  • 2,801
  • 3
  • 23
  • 35
0

You can use a separate table with pairs (task_id, index).

v.ladynev
  • 19,275
  • 8
  • 46
  • 67