T3 Stack Tutorial - Posts won't retain
Hello! I am new here and new to TS and React.
I am attempting to follow along with Theo's amazing T3 stack tutorial but have been running into an issue I was hoping someone would be able to assist with. Upon running the app, I keep getting the error:
prisma:query SELECT
trilldb
.Post
.id
, trilldb
.Post
.createdAt
, trilldb
.Post
.content
, trilldb
.Post
.authorId
FROM trilldb
.Post
WHERE 1=1 ORDER BY trilldb
.Post
.createdAt
DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
Ultimately what keeps happening is the posts won't retain on the app side but on the Prisma side they are.. Any suggestions?
I can provide further context, but does anyone have a quick solution for how they resolved this issue? I've tried searching online/stack overflow but to no avail.64 Replies
We might need to see the implementation of the router that calls posts.getAll and how it is called on the frontend but it can simply be a db mismatch issue. Make sure you have your
schema
file right, sync the db and generate types with npx prisma db push
, and check if data actually exists on db with npx prisma studio
Thank you for the suggestion. Unfortunately the issue persists.
What's happening is the post data exists on the db but I keep getting errors on the application and it just says "Something went wrong" instead of posting. I can post emojis but there is no record being maintained on the application.
could you post your schema and the actual code which is failing?
Here is the schema
Here is the code if you don't want to download:
could you wrap the code in ```
nvm that's all fine
do you know the code which is failing
As for what's failing, that is hard for me to determine. The following files have errors, but they all have to do with "Unsafe assignment of an
any
value" :
1. /src/pages/[slug].tsx
2. /src/pages/post/[id].tsx
3. /server/api/routers/posts.tsx
4. /components/postview.tsx
5. /server/api/helpers/filterUserForClients.ts
6. /server/api/helpers/ssgHelper.ts
The error code that is being thrown is mentioned in the body of the original post. There is another error code that actually occurs when I post which I can add as wellshow me your posts.getAll query?
yeah sure
you shouldn't have all those TS errors btw. Using TS isn't going to help much if you don't type things :p
Here is the error that I just got when posting an emoji:
yeah there's no way to tell anything from that. It's just showing prisma's prepared statements
are you sure the db is properly populated (check with prisma studio)? Otherwise, you're going to need to send some code
ie posts.getAll for a start
I'm running prisma studio, and the posts are all being recorded there
![](https://cdn.answeroverflow.com/1134651591727796314/Screenshot_2023-07-28_at_5.58.14_PM.png)
This is what I get on the app though:
![](https://cdn.answeroverflow.com/1134651903607848981/Screenshot_2023-07-28_at_6.01.02_PM.png)
I noticed there were a few things that were depracated that Theo was using in the video and I am super duper new to TS so a lot of this stuff goes way over my head. I figured this would just be a good way to throw myself into the deep end.. 😄
I really appreciate your help, meeps