P
Prisma7mo ago
charley

Why can't I access profile in user? (ORM) (Postgres)

With these models:
model User {
id Int @id @default(autoincrement())
email String @unique
profile Profile?
}

model Profile {
id Int @id @default(autoincrement())
userId Int @unique
user User @relation(fields: [userId], references: [id])
}
model User {
id Int @id @default(autoincrement())
email String @unique
profile Profile?
}

model Profile {
id Int @id @default(autoincrement())
userId Int @unique
user User @relation(fields: [userId], references: [id])
}
I can't access a user.profile and it doesn't exist in the User interface
Solution:
Fix: deleted and created my database instead of migration; i was using a completely different setup earlier and the migration must have corrupted some things
Jump to solution
4 Replies
charley
charleyOP7mo ago
I am doing
const user = await prisma.user.findUnique({
where: {
id: userId,
},
include: {
profile: true,
},
});
const user = await prisma.user.findUnique({
where: {
id: userId,
},
include: {
profile: true,
},
});
K1|ller
K1|ller7mo ago
are you using typescript? you'll get autocomplete in the case it exists
gaurav1998
gaurav19987mo ago
@charley I am getting the same exact issue as well. Are you using supabase by any chance?
Solution
charley
charley7mo ago
Fix: deleted and created my database instead of migration; i was using a completely different setup earlier and the migration must have corrupted some things
Want results from more Discord servers?
Add your server