Back

[solved]Relationship attribute between collections

  • 0
  • Web
Arti Gaund
25 Dec, 2023, 12:26

I have 2 collection skills and ProductContent. ProductContent have one to many relationship attribute connected with skills collections and skills collection have one to many relationship attribute connected with ProductContent collection. I want to store in ProductContent (skills=>collection of skills id's) and in skills (ProductContent=>collections of project id's) but i am getting server error and error type is unknown.

TL;DR
The user has a relationship attribute issue between two collections: ProductContent and skills. They want ProductContent to store a collection of skills' IDs, and skills to store a collection of ProductContent IDs. They initially set up a many-to-many relationship but encountered redundant data. The solution involves removing the IDs from the skills array before inserting it into the function. They suggested using the following code snippet: ```javascript const skillsMutate = skills.map(item => ({ technology: item.technology })); { ... skills: skillsMutate } ``` This code will extract only the technology property from each object in the skills array. The
Mosh Ontong
25 Dec, 2023, 12:50

As what I observed, you have One way attribute relationship in each collection.

Skill collections has One way attribute relationship of the ProductContent, and Similar to the ProductContent collection. I recommend use the Two way

Arti Gaund
25 Dec, 2023, 12:51

reason?

Mosh Ontong
25 Dec, 2023, 12:51

That could make effecient way

Mosh Ontong
25 Dec, 2023, 12:52

reason maybe it will create a new instance of attributes.

Mosh Ontong
25 Dec, 2023, 12:52

But base in your explanation that could make better

Arti Gaund
25 Dec, 2023, 12:53

my code is correct ?

Mosh Ontong
25 Dec, 2023, 12:53

can I see the sample value of skills in your code

Mosh Ontong
25 Dec, 2023, 12:53
Mosh Ontong
25 Dec, 2023, 12:54

and can I ask for screenshot of what is the error response of this issue

Mosh Ontong
25 Dec, 2023, 12:55

you can look the error response by using Insepct > Network Tab

Arti Gaund
25 Dec, 2023, 12:56

in technology, i am getting as [{id:"id1",technology:"reactjs"},{id:"id2",technology:"python}] and that i am including in skills

Arti Gaund
25 Dec, 2023, 12:57
Mosh Ontong
25 Dec, 2023, 13:02

[{id:"id1",technology:"reactjs"},{id:"id2",technology:"python}], if this is the sample value of skills in creating document within ProductContent. I aware that you include the id but seems your skills collection does not have id attribute. You can remove this one.

Arti Gaund
25 Dec, 2023, 13:04

so i should first remove id's from skills then insert it into the function

Arti Gaund
25 Dec, 2023, 13:05

?

Mosh Ontong
25 Dec, 2023, 13:10

if your code has id properties then yes. But if you dont want to delete it then

do this

TypeScript

const skillsMutate = skills.map(item => ({ technology: item.technology }));

{
 ... 
 skills: skillsMutate 
}

It will only extract the technology property

Arti Gaund
25 Dec, 2023, 18:07

i am using many to many for 2 way, but it storing redundant data

Mosh Ontong
26 Dec, 2023, 01:45

hmmmm, if I recall. The Business logic of your collection is that "The Product Content can contain many skills. While the skills only belong to one Product Content". If that the case you should set up into One to many.

Mosh Ontong
26 Dec, 2023, 01:46

If your previous solved you can edit this post into [SOLVED] if you have new issue please create new one.

Arti Gaund
26 Dec, 2023, 08:56

no ProductContent can contain many skills and skills contain many ProductContent

Arti Gaund
26 Dec, 2023, 10:42

[solved]Relationship attribute between collections

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