Back

[SOLVED] Relationship - Custom id for child document

  • 0
  • Databases
  • Flutter
hortigado
28 Jun, 2023, 14:40

Hi, I'm implementing appwrite with an offline first package. But I'm having problems with relationships because I need to get the id of the child document to create the local copy with the same id. The easiest thing would be to create another id attribute but I want to avoid this for two having two id fields. Is there a way to create the child document with a custom id?

TL;DR
The user was implementing Appwrite with an offline first package and was having trouble with relationships. They needed to get the ID of the child document to create a local copy with the same ID. They didn't want to create another ID field. The solution was to generate the ID locally using the provided code snippet.
hortigado
28 Jun, 2023, 14:47
TypeScript
        title: 'Spiderman',
        year: 2002,
        reviews: [
            { 
                $id: **CUSTOM ID**
                author: 'Bob', 
                text: 'Great movie!',
                $permissions: [
                    Permission.read(Role.any())
                ]
            },
        ]
    }```
Drake
28 Jun, 2023, 15:27
hortigado
28 Jun, 2023, 15:56

Hi, thanks, I needed that too. As for what generated an automatic id, it was my mistake that I was ignoring the upload of the $id attribute 😅 but hey, the generation of the id locally also needed

hortigado
28 Jun, 2023, 15:59

[SOLVED] Relationship - Custom id for child document

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