W
Wasp3w ago
cmilazzo

issue with entity id

I have a prisma entity defined as such: "model SurveyResult { id String @id result String reviews String @default("") analysis String @default("") idea Idea @relation(fields: [ideaId], references: [id]) ideaId Int }" I have an action that calls the entity create like this: const surveyResult = await context.entities.SurveyResult.create({ data: { result, idea: { connect: { id: ideaId } } }, id: reportId, }); However, I'm getting the error "Unknown argument for 'id'. Available options are marked with ?." Any suggestions?
3 Replies
kapa.ai
kapa.ai3w ago
Hi @cmilazzo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I see the issue with your entity creation. The problem is in how you're trying to set the id field in your Prisma create operation. When using Prisma through Wasp, the id should be included in the data object, not as a separate parameter in the create method. According to the Prisma API that Wasp uses, the correct way to structure your create operation is:
const surveyResult = await context.entities.SurveyResult.create({
data: {
id: reportId,
result,
idea: { connect: { id: ideaId } }
}
});
const surveyResult = await context.entities.SurveyResult.create({
data: {
id: reportId,
result,
idea: { connect: { id: ideaId } }
}
});
The error "Unknown argument for 'id'. Available options are marked with ?" occurs because you're passing id as a separate parameter to the create method, but Prisma's API expects all entity fields to be within the data object. When working with entities in Wasp, you're using Prisma's CRUD API under the hood Working with Entities, and the correct structure for creating entities follows Prisma's conventions. Let me know if this resolves your issue! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @cmilazzo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
cmilazzo
cmilazzoOP3w ago
Thank you @kapa.ai , that resolved the issue.
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You're welcome! I'm glad to hear that moving the id field into the data object resolved your issue. This is a common pattern when working with Prisma through Wasp, where all entity fields need to be included within the data object during creation operations. If you have any other questions about working with entities, Prisma, or other aspects of Wasp development, feel free to ask! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @cmilazzo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?

Did you find this page helpful?