Reputation: 11
I am using the AWS amplify project with react native, following their docs. I ran into an issue when I try and retrieve data. I cannot for the life of me work out how the return the child related objects along with it. I want all datasheets and all points related to the datasheets.
I set the depth value to 10, as the default was 2. Any ideas would be great!
Here is my GraphQL schema:
type Point @model {
id: ID! @primaryKey
points: Int!
models: String!
}
type Datasheet @model {
id: ID! @primaryKey
name: String!
points: [Point] @hasMany
}
here is some example data
point:
{
"id": "63",
"createdAt": "2023-06-19T21:23:40.548Z",
"datasheet": "51",
"models": "1 model",
"points": "800",
"updatedAt": "2023-06-19T21:23:40.548Z"
}
datasheet:
{
"id": "51",
"createdAt": "2023-06-20T08:21:32.281Z",
"name": "Stompa",
"points": [
"63"
],
"units": [
"51"
],
"updatedAt": "2023-06-20T08:21:32.281Z"
}
code to fetch datasheets:
console.log('GET datasheets');
const sheetData = await API.graphql(graphqlOperation(listDatasheets));
const sheets = sheetData.data.listDatasheets.items;
console.log(sheets[0].points.items);
console.log(sheets);
setSheets(sheets);
I tried a belongsTo on the points schema and that didn't work, and I figure I dont need to look up the relationship that way so I removed it again.
I am expecting a return of datasheets:[{ name: "Stompa", points: [{ models: "1 model" points: 800 }] }]
whats currently happening is i get the datasheet, but no points values.
Upvotes: 0
Views: 95
Reputation: 11
The Issue is with the data model. It is expected to have a field for the key like 'oneManyId'
for example for the above, datasheetPointsId
Added that and it's golden.
Upvotes: 0