Back

Help with database relationships

  • 0
  • Databases
  • Web
  • Cloud
Himanshu..πŸ₯‚
4 Apr, 2024, 01:55

so i have document named "uploads" and "users" both are in one way relation so i want to assign the upload to a particular user help me in that pls

TL;DR
Developers are seeking assistance with creating database relationships and assigning uploads to specific users. The provided code snippets show functions for creating uploads and sample user object structures. Solution: To establish a relationship between uploads and users, consider adding a field in the uploads document referencing the user who uploaded the file, such as a unique ID or username. This will facilitate linking uploads to their respective users.
Binyamin
4 Apr, 2024, 01:58

Let's say your users is like this

TypeScript
{ 
  name: ""
  uploads: {
    upload_file: ""
  }
}

Then you can do this

TypeScript
await databases.createDocument(
    DB_ID,
    COLLECTION_ID,
    ID.unique(),
    {
        name: 'Spiderman',
        uploads: [
            { upload_file: 'file'},
            { upload_file: 'file2'},
        ]
    }
)
Himanshu..πŸ₯‚
4 Apr, 2024, 01:58

specially on this func types

TypeScript
async function CreateUpload(msgId: string, fileId: string, fileSize: string, botType: string) {
  const promise = AppwriteDB.createDocument(
    process.env.APPWRITE_DATABASE_ID! || "65d4e2cb945b18ce913c",
    "65d4e325a9a679460393",
    fileId,
    { msgId: msgId, fileId: fileId, fileSize: fileSize, name: msgId, botType: botType }
  );
  promise.then(
    function (response) {
      return response;
    },
    function (error) {
      console.log(error);
    }
  );
}```
Himanshu..πŸ₯‚
4 Apr, 2024, 01:59

can you refer to this

Binyamin
4 Apr, 2024, 01:59

I don't see relationship in your code

Himanshu..πŸ₯‚
4 Apr, 2024, 01:59

user is already created just i want that when the user will upload any file

Binyamin
4 Apr, 2024, 01:59

What is the field of the user?

Himanshu..πŸ₯‚
4 Apr, 2024, 01:59

it will be in relation to it

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