Best way to save a ordered List to the Database while keeping the ordering

前端 未结 12 1090
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 17:27

I was wondering if anyone has a good solution to a problem I\'ve encountered numerous times during the last years.

I have a shopping cart and my customer explicitly

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 17:57

    I solved it pragmatically like this:

    1. The order is defined in the UI.

    2. The backend gets a POST request that contains the IDs and the corresponding Position of every item in the list.

    3. I start a transaction and update the position for every ID.

    Done.

    So ordering is expensive but reading the ordered list is super cheap.

提交回复
热议问题