Skip to content

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

Closed
prisma/prisma-engines
#2150

Description

@ehdrms785

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

Activity

  1. added
    kind/bug
    on Jul 3, 2021
  2. added
    bug/0-unknown
    bug/1-unconfirmed
    and removed
    bug/0-unknown
    on Jul 6, 2021
  3. matthewmueller commented on Jul 6, 2021

    @matthewmueller
    Contributor

    Can you share a reproduction script?

  4. pantharshit00 commented on Jul 6, 2021

    @pantharshit00
    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

  5. ehdrms785 commented on Jul 6, 2021

    @ehdrms785
    Author

    @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

  6. pantharshit00 commented on Jul 12, 2021

    @pantharshit00
    Contributor

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

    Candidating this.

  7. changed the title [-]Order By Relation with CursorId[/-] [+]Order By Relation with CursorId doesn't return result[/+] on Jul 12, 2021
  8. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Jul 12, 2021
  9. added this to the 2.30.0 milestone on Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug/2-confirmedkind/bugtopic: orderByRelation

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions