Back

For child document creation does only 1 layer nesting is supported?

  • 0
  • Databases
Vedsaga
9 May, 2023, 15:28

So, I this nested object

TypeScript
Business
-- Address
---- Pincode

So, for address I am sending the {...} body and as Pincode data base is pre-populated so, I am pne sending [...] pincode id in list.

TypeScript
{
 ...
 address: [ 
      {
      ...
      pincode: [
          "Pincode Document-Id"
        ]
    }
  ]
}

should this work? or does it only one layer of linking supported if so, then I would change my approach

TL;DR
The user is asking if only one layer of nesting is supported for child document creation. They provide an example JSON structure and ask if it will work. Other users confirm that nested linking should work and suggest checking the JSON for any errors. The user realizes they made a mistake in the previous JSON and provides the corrected version. They mention that the linking still doesn't work even for the first layer. Other users ask for more information, such as the response from the list collections API call. The user provides the response for the 'business' and 'address' collections. It is noticed that in the 'address' collection, the 'pincode
Drake
9 May, 2023, 15:46

This should be supported 🧐 3 levels

Vedsaga
9 May, 2023, 15:46

mm, let me once check the exact json body that is getting send paste here

Vedsaga
9 May, 2023, 16:00
TypeScript
 {
   "businessName": "x x Store",
   "ownerName": "xxxxx",
   "phoneNumberLink": {
     "primaryNumber": "xxxxxxx",
     "$permissions": []
   },
   "addressLink": {
     "locality": "xx",
     "pincodeLink": [
       "6453e9a738db8798e1f5     ],
     "$permissions": []
   }
 }

it seems valid to me at first glance

Drake
9 May, 2023, 16:28

the double quotes on pincodeLink don't look right

Drake
9 May, 2023, 16:28

also make sure you have access to that document

Vedsaga
9 May, 2023, 16:29

oh right 😞

Vedsaga
9 May, 2023, 16:29

ahh yaap, that actully had made it read for all user

Vedsaga
10 May, 2023, 09:25
TypeScript
{
    "businessName": "test",
    "ownerName": "Harshit Kumar",
    "phoneNumberLink": {
        "primaryNumber": "xxxxxxxx",
        "$permissions": []
    },
    "addressLink": {
        "locality": "Kanti",
        "pincodeLink": [
            "6453e9a738db8798e1f5"
        ],
        "$permissions": []
    },
    "businessTeamLink": [
        "645b620f9fca359ca91c"
    ]
}

I just checked the json again couple times, yestarday actually I made mistaking pasting here.. but agai as I check today json seems valid... still it is not getting linked

Vedsaga
10 May, 2023, 09:28
safwan
10 May, 2023, 10:21

I didn't understand the problem you're facing. Can you explain more please?

Vedsaga
10 May, 2023, 10:23

@safwan actully this one..

Vedsaga
10 May, 2023, 10:25

actully even first layer of linking does not work if you sending ids [...] in that format

Vedsaga
10 May, 2023, 16:07

πŸ‘€

safwan
10 May, 2023, 16:35

what do you mean by linking? are you using relations, or manually sending the data

Drake
10 May, 2023, 17:10

It should..i just tested it and the console does this too...

TypeScript
{
    "$permissions": [
        "read(\"user:6452e7df246ce0b0587b\")",
        "update(\"user:6452e7df246ce0b0587b\")",
        "delete(\"user:6452e7df246ce0b0587b\")"
    ],
    "level2": [
        "level2"
    ]
}
Vedsaga
11 May, 2023, 05:00

umm, very wired I wonder what is that I m doing wrong which is causing this ....

Vedsaga
11 May, 2023, 05:00

btw I am on 1.3.4

Drake
11 May, 2023, 05:09

Can you share the response from the list collections API call from the console? This way we can see all the attributes of the two collections

Vedsaga
11 May, 2023, 05:11

yaa sure, you mean when you refresh the page during that time those response body that is visible in network tab ?

Vedsaga
11 May, 2023, 05:19
TypeScript
{
   "$id":"64534af3c51c6287d5e3",
   "$createdAt":"2023-05-07T19:52:02.622+00:00",
   "$updatedAt":"2023-05-08T06:10:36.679+00:00",
   "$permissions":[
      "create(\"users\")",
      "read(\"users\")",
      "update(\"users\")"
   ],
   "databaseId":"6451d90b58e5630094e5",
   "name":"business",
   "enabled":true,
   "documentSecurity":false,
   "attributes":[
      {
         "key":"businessName",
         "type":"string",
         "status":"available",
         "required":true,
         "array":false,
         "size":50,
         "default":null
      },
      {
         "key":"ownerName",
         "type":"string",
         "status":"available",
         "required":true,
         "array":false,
         "size":100,
         "default":null
      },
      {
         "key":"addressLink",
         "type":"relationship",
         "status":"available",
         "required":false,
         "array":false,
         "relatedCollection":"64534dd42061cb7ff1f5",
         "relationType":"oneToOne",
         "twoWay":false,
         "twoWayKey":"64534af3c51c6287d5e3",
         "onDelete":"cascade",
         "side":"parent"
      },
      {
         "key":"phoneNumberLink",
         "type":"relationship",
         "status":"available",
         "required":false,
         "array":false,
         "relatedCollection":"64589deed43114bb68c2",
         "relationType":"oneToOne",
         "twoWay":false,
         "twoWayKey":"64534af3c51c6287d5e3",
         "onDelete":"cascade",
         "side":"parent"
      },
      {
         "key":"businessTeamLink",
         "type":"string",
         "status":"available",
         "required":true,
         "array":false,
         "size":30,
         "default":null
      }
   ],
   "indexes":[
      
   ]
}```
Vedsaga
11 May, 2023, 05:19

so this for business collection...

Vedsaga
11 May, 2023, 05:20
TypeScript
{
   "$id":"64534dd42061cb7ff1f5",
   "$createdAt":"2023-05-07T19:47:35.766+00:00",
   "$updatedAt":"2023-05-07T19:49:50.068+00:00",
   "$permissions":[
      "create(\"users\")",
      "read(\"users\")",
      "update(\"users\")"
   ],
   "databaseId":"6451d90b58e5630094e5",
   "name":"address",
   "enabled":true,
   "documentSecurity":false,
   "attributes":[
      {
         "key":"locality",
         "type":"string",
         "status":"available",
         "required":true,
         "array":false,
         "size":200,
         "default":null
      },
      {
         "key":"pincodeLink",
         "type":"relationship",
         "status":"available",
         "required":false,
         "array":false,
         "relatedCollection":"6453e48c14b3f046739b",
         "relationType":"manyToOne",
         "twoWay":false,
         "twoWayKey":"64534dd42061cb7ff1f5",
         "onDelete":"restrict",
         "side":"parent"
      }
   ],
   "indexes":[
      
   ]
}```
this is address json ( in this when trying to link pincode it is not getting linked
Vedsaga
11 May, 2023, 05:22

ah sending as child and expected to be created and also get linked

Drake
11 May, 2023, 06:03

if it's a many to one, you should be passing a single ID only rather than an array

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