I have got the understanding that creating relations between type create an collection which keeps the data for relationships keeping reference id for task collection and user collection. so the thing I was trying earlier was not correct.
For many-to-many relationships, this is correct. We have documentation describing how relationships are implemented depending on your GraphQL schema.
One-to-many relationships do not need an intermediate Collection. But you do need to make sure that you define your schema using the @relation directive appropriately for the type of relationship you need.
so that means we need to defined relationship like this
type Tasks{
id
taskname
user: User
}
type User{
id
email
tasks: [Task] @relation
}
so for this one to many relationship user field must be there in type Tasks. what if we want to keep tasks in type User only and not want to keep user inside type Tasks. is that feasible.
like this is one to many relationship and I understood only many to many would require an intermediate table.
This schema will put a reference to the User in each Tasks document. An index is then used to fetch all tasks for a given user. e.g.
query {
findUserByID(id: "101") {
_id
email
tasks {
# essentially the result of
# `Paginate(Match(Index("tasks_user_by_user"), user))`
data {
_id
taskname
}
}
}
}
No intermediate collection is required, because the relationship is stored directly in one of the collections and accessible either directly or through the index.