I have two tables: web_conference is a one to many with the second child table conference_users.
I am attempting to use strapi.entityService to create a new entry to the web_conference and conference_users table like so:
const mapInvites = async ()=>{
return inviteList.conferenceUsers.map(async (item)=>{
let result = {
userId:item.userId,
sessionId:item.sessionId
}
return result
})
}
try {
const newParentObject = await strapi.entityService.create('api::web-conference.web-conference',{
populate:true,
data:{
ownerId:userUid,
sessionId:sessionId,
title:title,
date:date,
startTime:startTime,
endTime:endTime,
publishedAt: publishedAt,
conference_users:await Promise.all(await mapInvites()),
inviteRequired:inviteOnly}
});
}
catch (error) {
console.log(error)
}
However,I keep getting the error
message:'Undefined attribute level operator conference_users'
name: 'ValidationError'
I have no idea how to solve this and have been stuck for quite some time.
I simply want to be able to populate these tworelational tables. Can someone offer assistance?
I have added the schema.json below:
{
"kind": "collectionType",
"collectionName": "conference_users",
"info": {
"singularName": "conference-user",
"pluralName": "conference-users",
"displayName": "ConferenceUser",
"description": ""
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"userId": {
"type": "string"
},
"sessionId": {
"type": "string",
"required": true
},
"web_conference": {
"type": "relation",
"relation": "manyToOne",
"target": "api::web-conference.web-conference",
"inversedBy": "conference_users"
}
}
}
{
"kind": "collectionType",
"collectionName": "web_conferences",
"info": {
"singularName": "web-conference",
"pluralName": "web-conferences",
"displayName": "WebConference",
"description": ""
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"sessionId": {
"type": "string",
"required": true,
"unique": true
},
"title": {
"type": "string",
"required": true
},
"date": {
"type": "string"
},
"startTime": {
"type": "string"
},
"endTime": {
"type": "string"
},
"inviteRequired": {
"type": "boolean",
"required": true,
"default": false
},
"ownerId": {
"type": "string"
},
"conference_users": {
"type": "relation",
"relation": "oneToMany",
"target": "api::conference-user.conference-user",
"mappedBy": "web_conference"
}
}
}
try {
const newParentObject = await strapi.entityService.create('api::web-conference.web-conference',{
data:{
ownerId:userUid,
sessionId:sessionId,
title:title,
date:date,
startTime:startTime,
endTime:endTime,
publishedAt: publishedAt,
conference_users:[{id:0,userId:"eeeeee",sessionId:"333-333"}],
inviteRequired:inviteOnly}
});
}
catch (error) {
console.log(error)
}
Hi your missing pieces of code:
const mapInvites = async () => {
return inviteList.conferenceUsers.map(async (item) =>
await strapi.entityService.create('api::conference-user.conference-user', {
data: {
userId: item.userId,
sessionId: item.sessionId
}
})
)
}
try {
const newParentObject = await strapi.entityService.create('api::web-conference.web-conference', {
data: {
ownerId: userUid,
sessionId: sessionId,
title: title,
date: date,
startTime: startTime,
endTime: endTime,
publishedAt: publishedAt,
conference_users: await Promise.all(mapInvites),
inviteRequired: inviteOnly
}
});
}
catch (error) {
console.log(error)
}
not tested so may not work )