Back

[SOLVED] Relationships IDs

  • 0
  • Web
Kenny
12 May, 2023, 01:00

I have two questions with relationships.

  1. How can I define an ID in the relationed item being added.
TypeScript
    .createDocument("645c032960cb9f95212b", "album", track.album.id, {
      name: track.album.name,
      href: track.album.external_urls.spotify,
      popularity: track.album.popularity,
      images: track.album.images?.map((image) => image.url) ?? [],
      artist: [{
          name: track.artists[i].name,
          href: track.artists[i].external_urls.spotify,
          popularity: track.artists[i].popularity,
          images: track.artists[i].images?.map((image) => image.url) ?? [],
          genres: track.artists[i].genres ?? [],
      }],
      track: [{
          name: track.name,
          href: track.external_urls.spotify,
          popularity: track.popularity,
          preview: track.preview_url,
          explicit: track.explicit,
          duration: track.duration_ms,
      }],
    })

With this code above how can I explicitly set the ID for Artist and Track.

  1. How can I relate a new item to an existing item?
TL;DR
[SOLVED] Relationships IDs The OP was able to find a solution to their problem. They wanted to explicitly set an ID for an artist and track when creating a document. To do this, they needed to modify their code and set the $id attribute to the desired ID. They also wanted to know how to relate a new item to an existing item, and they were informed that they don't need to explicitly link them as the child document will automatically be linked to the parent document.
Vedsaga
12 May, 2023, 02:23

hi Kenny, so what you are trying to do here is creating a child document on the fly which actually auto-matically link with Parent Document so you don't need to explicitily link here

Kenny
12 May, 2023, 02:52

Yea, but in another query at a later time I want to then relate a new item with an existing track.

Vedsaga
12 May, 2023, 04:02

yes you can archive that you just use update

Drake
12 May, 2023, 04:03

And pass an array of artist/track document ids

Drake
12 May, 2023, 04:04

As for specifying an id, set the $id attribute to whatever you want the id to be

Drake
12 May, 2023, 04:06

example:

TypeScript
{
    "level2": [
        {
            "$id": "level2",
            "level3": [
                {
                    "$id": "level3",
                    "level4": [
                        {
                            "$id": "level4",
                            "level5": [
                                {
                                    "$id": "level5"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}
Vedsaga
12 May, 2023, 04:07

oh level 5 nesting is support, didn't knew πŸ‘€

Drake
12 May, 2023, 04:10

Nope lol

joeyouss
12 May, 2023, 07:30

only 3 levels

joeyouss
12 May, 2023, 07:32

Can I close this if resolved @Vedsaga @Kenny

Vedsaga
12 May, 2023, 07:33

cc @Kenny actually he initially asked

Kenny
12 May, 2023, 11:39

Thanks everyone! This got me what I needed.

Drake
12 May, 2023, 15:28

[SOLVED] Relationships IDs

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