
Hello! I am trying to make a relation ship with students, parents, and class. Students can contain 1 parent while parents can contain many students. Same with classes. However, when trying to link those relationships using document IDs it does not work. Please help....
Here is the code:
import { appwriteDatabases,appwriteUser } from "$lib/appwrite";
import { DB_ID,COLLECTION } from "$lib/ids";
import { Query,ID } from "appwrite";
let uuid = '';
let parentDBID = '';
let children = [] as any[];
let newChildName = '';
let newChildClass = '';
async function addChild() {
console.log(newChildName);
console.log(newChildClass);
console.log(parentDBID);
await appwriteDatabases.createDocument(DB_ID,COLLECTION.Students,ID.unique(),
{
Name:newChildName,
// remove the space at the end
class:[newChildClass],
parents:[parentDBID]
}
).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
}
async function getChildren() {
appwriteUser.get().then((res) => {
uuid = res['$id'];
console.log('UUID '+uuid);
appwriteDatabases.listDocuments(DB_ID,COLLECTION.Parents,[Query.equal('uid',[uuid])]).then((res) => {
parentDBID = res.documents[0]['$id'];
children = res.documents[0]['students'];
console.log(children);
}).catch((err) => {
console.log(err);
});
}).catch((err) => {
console.log(err);
});
}
getChildren();
NOTE: The variable newChildClass is a DB id... please help!

On the console it shows n/a. There are 0 errors....

@Steven can u help please?

Please don't tag people as it can be very disruptive. Just post and wait

what's it say if you look at the JSON for the document?

It does not show

this is it pretty much

nothing about the relations

what are the permissions on the related collections?




its the same for all 3 collections

If a student can only have 1 parent, why are you passing an array?

oh...

I thought the square brackets were required....

it works tyms!

[SOLVED] Need help with relationships
Recommended threads
- Stuck in "deleting"
my parent element have relationship that doesnt exist and its stuck in "deleting", i cant delete it gives me error: Collection with the requested ID could not b...
- Help with 409 Error on Relationship Setu...
I ran into a 409 document_already_exists issue. with AppWrite so I tried to debug. Here's what I've set up: Collection A has 3 attributes and a two-way 1-to-m...
- Database Double Requesting Error.
I am getting error for creating new document in an collection with new ID.unique() then too getting error of existing document. When button is pressed one docum...
