Skip to content
Back

Is there a way to reorder the list of relationships in appwrite?

  • 1
  • Databases
  • Flutter
Tomic R.
28 May, 2023, 05:52

Appwrite relationships are great. I have a relationship with one to many. So one Document stores multiple ids. But is there a way to (programatically) reorder this list?

TL;DR
The user is asking if there is a way to reorder the list of relationships in Appwrite. Some users suggest using an integer attribute 'order' to sort them better. It is mentioned that the relationships are currently returned based on their creation time, but the user wants to keep them in a specific order. There is no clear solution provided in the thread.
safwan
28 May, 2023, 06:24

Not sure what exactly you mean. Do you want to re-order the way they're returned?

Tomic R.
28 May, 2023, 07:14

yep. For example, that the current 3rd value is becoming the 2nd.

Tomic R.
28 May, 2023, 07:21
Argel
31 May, 2023, 06:01

So you want to keep the order of the relationships the way they are inserted? Or if you edit them from the other side into: artictleBlocks: [id1, id2, id3], to have them returned in that order? And if you add a new block id4 that is linked to the Article to be added at the end, resulting in id1, id2, id3, id4?

safwan
31 May, 2023, 06:10

I'm not sure of how relations fully work, but I'm pretty sure that the order of the IDs in the relationship are chronological. So whenever a child is created, it gets attached to the end of the list. I'd like to assume that's the expected behaviour, as you can filter/sort your lists on the client side

Vedsaga
31 May, 2023, 06:27

why would you like to do it? order generally doesn't have any impact

Argel
31 May, 2023, 06:36

Yeah, they are returned based on their creation time. I was testing it now.

Argel
31 May, 2023, 06:38

I guess he wants to keep them in his defined order, without needing a special attribute for it such as having on each ArticleBlocks attribute int order.

safwan
31 May, 2023, 07:25

Aha that makes sense. @Tomic R. you should look at this idea of using an integer attribute order to help you sort them better.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more