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

orderBy Relation Issue #1071

Open
airidasj opened this issue Apr 29, 2021 · 0 comments
Open

orderBy Relation Issue #1071

airidasj opened this issue Apr 29, 2021 · 0 comments

Comments

@airidasj
Copy link

Hi guys,

An amazing feature you made there, works as expected for most cases except theres an interesting case.

The query:
colors( orderBy:{ main_color: {count: desc} } }

The model:
model Color { id Int @id @default(autoincrement()) color_profiles ColorProfile[] products ProductContainer[] hex String @unique background String? main_color SingleProduct[] @relation("MainProductColor") frame_color SingleProduct[] @relation("ProductFrameColor") colors_related Color[] @relation("ColorToColor") // colors related to me (this color) }

Basically, i have Color relations to product properties, a product can have a main color and a frame color etc...

What i want, is to sort by the amount of products this color is associated with (biggest to smallest by frame_color).

It works, when the relation field has connections.

It fails, when the relation field is an empty array. When we have desc, the 0 values are at the top (the arrays that have null connections), then we start to get to the largest values after them and go down (see the picture). When we have 'asc', the null arrays are treated as the highest COUNT aggregate value we start from 1, go to biggest value and we get 0 values (null arrays).

Screenshot-2021-04-29-at-18-56-13

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

1 participant