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

Order By Relation with CursorId doesn't return result #8036

Closed
Tracked by #8628
ehdrms785 opened this issue Jul 3, 2021 · 4 comments · Fixed by prisma/prisma-engines#2150
Closed
Tracked by #8628

Order By Relation with CursorId doesn't return result #8036

ehdrms785 opened this issue Jul 3, 2021 · 4 comments · Fixed by prisma/prisma-engines#2150
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: orderByRelation
Milestone

Comments

@ehdrms785
Copy link

ehdrms785 commented Jul 3, 2021

Bug description

< This is my latest bug report >

I am currently using the preview version of 'Order By Relations'.
There is a bug that ignores the same value (when count value is 0).
When I order(sort) by the number of people who press like,
if the value is zero(ex: A => likeCountPerson:0 , B=> likeCountPerson:0), prisma ignores it.

DataModel seems like this.

model Post {
  likeCountPeople Person[]
}

model Person {
}
client.post.findMany ({
  // ...
  orderBy: {
    likeCountPeople: { _count: "desc" },
  }
})

< I found why it doesn't work well i expected >

When I tried to move it again, there was no problem with that part.
But when i get order by the number of people who press like with cursorId,
prisma ignores it. OrderBy Relation with CursorId ignores " _count value is zero" is the key.

When I order By likeCountPeople _count "desc" with no CursorId,
5 Data comes out ( Including having zero data )

 "data": { 
  [
    "post1": 
        {
          "id": 1,
          "likeCountPeople" : {
                 <Person 1>,
                  <Person 2>,
                   <Person 3>
            }
        },
       "post2": 
          {
          "id": 2,
            "likeCountPeople" : {
                   <Person 1>,
                    <Person 2>,
                     
              }
          },
    "post3": 
        {
          "id": 3,
          "likeCountPeople" : {
                 <Person 1>,
            }
        },
    "post4": 
        {
          "id": 4,
          "likeCountPeople" : {
                  NO PERSON
            }
        },
    "post5": 
        {
          "id": 5,
          "likeCountPeople" : {
                  NO PERSON
            }
        },
    ]
  }

But , When I order By likeCountPeople _count "desc" with CursorId, Prisma ignores if _count value is zero.

           ...(cursorBakeryId && { cursor: { id:  1} }),
          skip: cursorId ? 1 : 0,
          take: 5,
          orderBy: {
              likeCountPeople: { _count: "desc" },
          }, 

2 Data comes out ( It should be to have four data except for one data that be skipped )
But the data that _count == 0 (count value is zero) is ignored .

 "data": { 
  [
       "post2": 
          {
          "id": 2,
            "likeCountPeople" : {
                   <Person 1>,
                    <Person 2>,
                     
              }
          },
    "post3": 
        {
          "id": 3,
          "likeCountPeople" : {
                 <Person 1>,
            }
        },
    ]
}

How to reproduce

Expected behavior

When I orderBy Relation with cursorId, output data should be include if _count value is zero.
Of course, it goes well if i don't use cursorId.

Prisma information

Environment & setup

  • OS: Window 10 Pro
  • Dataase: PostgreSQL,
  • Node.js version: v12.16.3

Prisma Version

prisma               : 2.24.1 
@prisma/client       : 2.24.1 
Current platform     : windows
@ehdrms785 ehdrms785 added the kind/bug A reported bug. label Jul 3, 2021
@janpio janpio added topic: orderByRelation team/client Issue for team Client. labels Jul 4, 2021
@matthewmueller matthewmueller added process/candidate bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. and removed process/candidate bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Jul 6, 2021
@matthewmueller
Copy link
Contributor

matthewmueller commented Jul 6, 2021

Can you share a reproduction script?

@pantharshit00
Copy link
Contributor

@ehdrms785 Can you please also try this with latest version 2.26? Also, as Matt mentioned, please try to share a isolated reproduction. The above setup with take lot of manual setup in order for us to reproduce a problem.

Here is an example reproduction: https://github.com/harshit-test-org/prisma-issue-7007

@ehdrms785
Copy link
Author

ehdrms785 commented Jul 6, 2021

@ehdrms785 Can you please also try this with latest version 2.26? Also, as Matt mentioned, please try to share a isolated reproduction. The above setup with take lot of manual setup in order for us to reproduce a problem.

Here is an example reproduction: https://github.com/harshit-test-org/prisma-issue-7007

@pantharshit00
I tried version 2.26, but it was same result.
Here is the reproduction script :) I don't know I did well but I tried.
If it was something wrong please let me know.
https://github.com/ehdrms785/prisma-issue-8036

@pantharshit00
Copy link
Contributor

Thanks for the reproduction repo, I can confirm this bug using that.

Candidating this.

@pantharshit00 pantharshit00 changed the title Order By Relation with CursorId Order By Relation with CursorId doesn't return result Jul 12, 2021
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. process/candidate and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jul 12, 2021
@matthewmueller matthewmueller added this to the 2.30.0 milestone Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: orderByRelation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants