Hey guys. I am looking for a proper solution on ho...
# orm-help
v
Hey guys. I am looking for a proper solution on how we can achieve specific order positions. For example we want to query todos by priority. We could add a priority INT field, but changing a one todo priority will require us to update all following records. Any suggestions?🙏
j
if you want something like sort functionality you can try orderBy property I guess. For eg:
Copy code
prisma.user.findMany({
  orderBy: [
    {
      role: 'desc',
    },
]
})
v
@Jayanth year. But i mean I want to have a reorder functionality. Where you can move things around
Each time you tome item from position 3 to 17, you will need to update all other items to change position
j
OK. I have a solution but not so clean one I guess. For example lets say you have 20 items then give priority like 20,40,60....400. Advantage is when you move third item which has priority 60 to 17. Update its priority to 361 kind of. so you dont have to update other stuff. Still everything stays in order. This is not optimal for sure. But it works I guess
But if you move item to 17 position 20 times this breaks. 😂
v
@Jayanth well, we can use Double instead of Int and divide it by 2 million of times)
💯 1
j
@vnadygin Yea, That works. 👏