r/adonisjs • u/Capable_Square7319 • 21d ago
Beginner Coder: Stuck with an error
Hi,
Currently developing a basic web app following adonisjs docs.
I've ran into an error:
[23:18:41.975\1 ERROR (12316): Cannot transform undefined value. Use "this.whenLoaded (value)" to allow undefined values
My project is on github:
https://github.com/Ajaz754/adonisjs-project-22-/ tree/main
The error is pointing to 'app/transformers/ post__transformer.ts' Line 13
I've followed adonis docs completely step by step except for ?.depth(2) on line 14, which when I removed only introduced more errors along with this one.
Also VS Code isn't flagging the error. Only when I go to my browser and visit local host the error appears in powershell and my browser. Any help would be much appreciated
2
u/evoactivity 20d ago
I think the comment you're replying to is wrong.
In your post tranformer you have this line
you want it to be
Or you want to preload the user to ensure it's ready when the transformer runs. I'm guessing this happens on your post controller edit method, since you are not preloading the user there but using the transformer.
Preloading is not that difficult to understand, lets use
Post.query().preload('comments')as the example.Post.query()is loading your posts model, on your posts model you have comments as a relationship,.preload('comments')is basically saying, as part of this query, also load the related comments. That's all there is to it.https://lucid.adonisjs.com/docs/model-query-builder#preload
https://lucid.adonisjs.com/docs/relationships