Back

two way relationship question

  • 0
  • Databases
  • Web
aliens3
5 Mar, 2024, 15:03

When I create a two way relationship and select for example one to many ( eg. one survey -> many questions), in the related collection it is created also as one to many (one question -> many surveys).. is this as expected ?

TL;DR
Developers are discussing the possibility of creating a "child" document in one collection and automatically updating a "parent" document in another collection to establish a two-way relationship. It seems like a possible typo in the documentation as the experience indicates it should work as expected. The structure of the relationship should reflect one-to-many in both collections.
Kenny
5 Mar, 2024, 15:07

If it's two way then both collections will have a relationship to each other

Kenny
5 Mar, 2024, 15:07

I think if you did a one to many, the other collection would actually be a many to one, unlike what you have above.

aliens3
5 Mar, 2024, 15:13

I would have expected that but it looks like this

Kenny
5 Mar, 2024, 15:28

huh, yea, I can see that in my own project too. Wonder if that's just a typo mistake? I believe it works as you would expect. At least that's my experience.

aliens3
5 Mar, 2024, 15:43

Thank you, maybe that's the case, and it' just a typo

aliens3
5 Mar, 2024, 15:46

In this case, would it be possible to create a "child" document in the questions collection and automatically update an existing "parent" document in the surveys collection ? The documentation only shows the other way around

Kenny
5 Mar, 2024, 15:58

If it's two way I think you can do

TypeScript
databases.createDocument('[DATABASE_ID]', 'Survey', '[DOCUMENT_ID]', {
  questions: [...questions]
});

OR

databases.createDocument('[DATABASE_ID]', 'Question', '[DOCUMENT_ID]', {
  survey: survey
});
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