Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown arg page #4

Open
cakctus opened this issue Dec 30, 2022 · 1 comment
Open

Unknown arg page #4

cakctus opened this issue Dec 30, 2022 · 1 comment

Comments

@cakctus
Copy link

cakctus commented Dec 30, 2022

await paginate(await prisma.cars_model, {
where: {
cars_generation: {
every: {
cars_modification: {
every: {
body_type: {
contains: bodyType,
},
},
},
},
},
},
include: {
cars_generation: {
include: {
cars_modification: {
where: {
body_type: {
contains: bodyType,
},
},
},
},
},
},
take: 10,
skip: 0,
page: page,
})
Screenshot_8

I am trying to implement this code
const result = await paginate<User, Prisma.UserFindManyArgs>(
prisma.user,
{
where: {
name: {
contains: 'Alice'
}
}
orderBy: {
id: 'desc',
}
},
{ page: query.page }
})

@smohammadhn
Copy link

The paginate function takes three arguments.

first: only the model. (prisma.cars_model)
second: findMany options. (only one object containing all the options except skip & take) ({ where, include, ... })
third: The pagination option which are ({ perPage: 10, page: 1})

await paginate(prisma.cars_model, {
  where: {
    cars_generation: {
      every: {
        cars_modification: {
          every: {
            body_type: {
              contains: bodyType,
            },
          },
        },
      },
    },
  },
  include: {
    cars_generation: {
      include: {
        cars_modification: {
          where: {
            body_type: {
              contains: bodyType,
            },
          },
        },
      },
    },
  },
},
{ page, perPage: 10}
)

Also, you don't need to await the first argument, it's just a reference to your model so that the paginate function later invokes .count and .findMany of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants