Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

1

450
Views
Prisma findMany function is not returning relational data

I am trying to populate my data with relational data using Prisma 2.28.0, Here is my

Schema.prisma model below

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Product {
  id           Int         @id @default(autoincrement())
  name         String         @db.VarChar(255)
  transactions Transaction[]
}

model Transaction {
  id        BigInt   @id @default(autoincrement())
  quantity  Int
  time      Int
  product  Product? @relation(fields: [productId], references: [id])
  productId Int?
}


the function I am trying to fetch data.

const { PrismaClient }=require("@prisma/client")

const prisma = new PrismaClient()

async function checkPrismaConnection(){
    try {
        const result=await prisma.product.findMany();
        console.log(result);
    }catch (e) {
        console.log(e);
    }
}

 checkPrismaConnection();

OutPut

[
  { id: 1, name: 'John Doe' },
  { id: 2, name: 'Masum' },
  { id: 3, name: 'Rezaul' }
]

Transaction DB result enter image description here

Product DB

enter image description here

I don't know why my findMany() is not retuning relational db data. Thank you

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

 const get = await prisma.post.findMany({ where: { title: { contains: 'cookies', },}, include: { author: true, // Return all fields },
})

The "Including Deep Nested Relationships" chapter a bit further down actually uses a .category field that is also an array, as in your example with .transactions .

about 4 years ago · Juan Pablo Isaza Report

0

Clean must set include to true.

So the code will look like this for you

 const PrismaClient = require("@prisma/client")

const prisma = new PrismaClient()

async function checkPrismaConnection(){
 try {
 const result=await prisma.product.findMany();
 console.log(result);
 }catch (e) {
 console.log(e);
 const get = await prisma.post.findMany({ where: { title: { contains: 'cookies', },}, include: { author: true, // Return all fields },
}
 }


 checkPrismaConnection();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!