Back

create associated documents, using relationships, though SDK

  • 0
  • Functions
  • Storage
sevla
17 Apr, 2024, 00:10

I have a collection which has an association 1:1 two-way with another collection. and now trying to create a document in each collection at same time the code:

` // initialize two unique ids const id01 = await sdk.ID.unique(); const id02 = await sdk.ID.unique();

TypeScript
  // create the document content and
  // try assign those IDs to fill the relationships
  const db1_row = { total: TOTAL, dB002: `${id02}` };
  const db2_row = { factor_a, factor_b, dB001: `${id01}` };

  // create both documents
 await databases.createDocument(DB, COL_DB02, id02, db2_row);
 await databases.createDocument(DB, COL_DB01, id01, db1_row);

the attributes that has the association are dB002 and dB001`. running this code doesn't though error, and the documents are created, but without the association

there's a proper way of doing it?

TL;DR
Developers want to create associated documents simultaneously using relationships through the SDK. They are encountering issues while attempting to establish links between the two documents. The current code creates documents without the associations. To address this, they should create both documents in one API call. Additionally, they should ensure that the association IDs are properly assigned within the document content.
Steven
17 Apr, 2024, 01:25

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Steven
17 Apr, 2024, 01:27

You can't really do that because the document doesn't exist...I would create both documents in 1 API call

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