TypeError: Cannot read properties of undefined (reading 'id')
I am having issues with creating an entity using nested relations in Prisma. I don't think this is a wasp issue but I wanted to ask to make sure. The only thing I am wondering about is in case I am missing some setup in the
main.wasp
file.
Happening in file src/actions.js
on https://github.com/ksk385/c2log-app
4 Replies
Hi @Karan. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but I can't provide a specific solution to your problem as the provided knowledge sources don't contain the exact information about the issue you're facing. However, I can give you some general advice based on the information available.
In Wasp, when you're creating an entity using Prisma, you need to make sure that the entity is properly defined in your
main.wasp
file and that it's included in the entities
array of the action that's using it. Here's an example from the Wasp documentation (https://wasp-lang.dev/docs/data-model/operations/actions#using-entities-in-actions):
In your action function, you can then access the entity through the context
argument:
If you're getting a TypeError: Cannot read properties of undefined (reading 'id')
, it might be because you're trying to access a property of an object that hasn't been initialized. Make sure that the object you're trying to access and its id
property exist before you try to use them.
If you continue to have issues, I would recommend checking the Wasp documentation (https://wasp-lang.dev/docs) and the Prisma documentation (https://www.prisma.io/docs/) for more information.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Karan, 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?There is nothing special you need to set in main.wasp! It sounds to me like your args.userId is maybe not defined. Might be due to how you are calling that action? Have you tried logging
args
in the action to make sure they look like what you expect them to look like?Figured it out - the problem was that I was not awaiting for the promise to resolve
Ah makes sense, I completely missed it!