Rank 3: Container
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!