How to save a particular, mutable “order” into a database

后端 未结 9 924
北恋
北恋 2021-02-05 03:34

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
  • Muffin
9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 04:05

    You can user previous Id, every new insertion you set last inserted row ID as previous ID like this,

    table, td {
      border: .2px solid black
    }
    ID NAME PREV_ID
    1 first_item <null>
    2 second_item 1
    3 thid_item 2

    any time you reordering easily insert with last row id, If you use next id every new insertion you need to update previous one, If you use sort order in any update you have to update multiple rows. Now postgreSQL recursive query available for selecting

提交回复
热议问题