I am doing a WRITE using Create in FQL into a collection say “Question”. Question has attribute called “tags” that is in a many-to-many relation with collection “Tag”. There exists tag(s) called “A” or many, and when I’m creating a new document in “Question”, I want to refer that/those tag(s) in my “tags” attribute.
I tried using
q.Create(q.Collection(“Question”), {
data: {
title: “----”,
timestamp: 1607521854475,
tags: [q.Ref(q.Collection(“Tag”), “284439611044790785”)]
}
}
But it won’t fetch me any values for tags when I query my “Questions” collection.
(I would like to know the syntax. I assume I’m trying to find the “connect” feature of graphQL).
In a many-to-many relationship, the relationship between questions and tags aren’t stored in question or a tag document. Rather, the system creates a new collection where the documents have a property to store a tag reference and a property to store a question reference. And then 3 indexes are created (find all tags for a question, find all questions for a tag, find all relations belonging to a question+tag)
So to add a relationship between a question and a tag, you need to add a new document to that question_tag collection with the appropriate references set in it.
1 Like