Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Order by related fields #95

Closed
marktani opened this issue Feb 9, 2017 · 49 comments · Fixed by Skitionek/prisma#24 · May be fixed by ajesse11x/prisma#60
Closed

Order by related fields #95

marktani opened this issue Feb 9, 2017 · 49 comments · Fixed by Skitionek/prisma#24 · May be fixed by ajesse11x/prisma#60

Comments

@marktani
Copy link
Contributor

marktani commented Feb 9, 2017

Example: a User has many Posts. Should be possible to order the Posts by User name.

Maybe:

query {
  allPosts(orderByRelated: [user_name_ASC]) {
    id
  }
}
@cameronk
Copy link

This would be a lifesaver!

@edtsech
Copy link

edtsech commented Jul 12, 2017

@marktani any workaround we can use for the time being?

@marktani
Copy link
Contributor Author

The best workaround I'm aware of, is to order items client side 🙂

@shanecav
Copy link

shanecav commented Aug 5, 2017

It would be great to be able to order by "to-many" related fields as well (by the count of related items).

For example, to get a list of the top 10 most voted-for links (assuming votes is a related field of type [Vote!]!):

query {
  allLinks(first: 10, orderBy: votes_DESC) {
    id
    url
    description
    _votesMeta {
      count
    }
  }
}

Currently, to get that list you'd have to query for every Link and then sort/slice it on the client, which is potentially a ton of overfetching.

@kenyk7
Copy link

kenyk7 commented Oct 20, 2017

A question for when they plan to add this improvement?

@studentIvan
Copy link

+1 for this

@jeromeky
Copy link

jeromeky commented Nov 5, 2017

+1

1 similar comment
@danstepanov
Copy link

+1

@serverlesspolska
Copy link

I see a lot of 👍
Dear GraphCool when do you plan to implement that?

@martinsura
Copy link

Must-have feature!

@schickling schickling added this to the 1.1 milestone Jan 6, 2018
@marktani marktani removed this from the 1.1 milestone Jan 22, 2018
@danrasmuson
Copy link

In my case this table will have thousands of rows. My users won't be able to sort the table by "createdBy" or "dataset" until this feature lands.

screen shot 2018-02-24 at 11 47 25 am

@studentIvan
Copy link

@danielrasmuson you can create some sortable index just as temporary solution :)

@PascalSenn
Copy link

Have a look at #62
This would solve the issues:

query{
  servers(
  orderBy: {
    active: DESC
    assetNumber: ASC
    customer: {
        name:ASC 
   }
  }
  ) {
    id
    active
    assetNumber
    customer {
         name
    }
  }
}

@harrisrobin
Copy link

+1

1 similar comment
@iyeremuk
Copy link

+1

@craigcbrunner
Copy link

Please add this and order by multiple fields!

@darthmolly
Copy link

darthmolly commented Mar 14, 2019

+1

@nk1tz
Copy link

nk1tz commented Mar 23, 2019

+1
I have a need for exactly this.
:)

@aandriamanga
Copy link

+1 💯

@terion-name
Copy link

terion-name commented Apr 1, 2019

VERY needed

@kumarabhirup
Copy link

is it yet not built???? how do I order my posts by number of upvotes???

@impowski
Copy link

Would be an amazing feature

@fenos
Copy link

fenos commented May 1, 2019

Any update on this?

@bkstorm
Copy link

bkstorm commented May 10, 2019

it's a really important feature. This issue was created two years ago and hasn't been fixed.

@valentinbe
Copy link

valentinbe commented May 10, 2019

Definitely agree, we are patiently waiting for this feature to push Prisma to production here :)

@juliosampaio
Copy link

Any update on this?

@jvlobo
Copy link

jvlobo commented May 26, 2019

Any update on this??? :(

@steebchen
Copy link
Contributor

Can people please stop spamming this thread with "UPDATES????" and instead upvote the first comment? I does not help anything, they are currently working on Prisma 2 (where this feature will be integrated) and that will take a while. In the meantime, you're just notifiying 35 participants with no new information and thus wasting their time. I think they will update us once this feature is implemented.

@jvlobo
Copy link

jvlobo commented May 27, 2019

Can people please stop spamming this thread with "UPDATES????" and instead upvote the first comment? I does not help anything, they are currently working on Prisma 2 (where this feature will be integrated) and that will take a while. In the meantime, you're just notifiying 35 participants with no new information and thus wasting their time. I think they will update us once this feature is implemented.

I upvoted the first comment months ago.
I guess people wouldn't "spam" if the Prisma team was a little bit more communicative, don't you think?

@iwasingh
Copy link

Another workaround to avoid ordering client-side is to put an index attribute on the model related to another field

type Vendor {
 id: ID!
 name: String
} 

type Product {
  _vendor_name: String
 vendor: Vendor
}

You have to handle _vendor_name updates manually but then you can

query {
  products(orderBy: _vendor_name_ASC) {  
   id 
   name
   vendor {
     name
    } 
  }
}

Yeah it's cumbersome, but works fine

If you want ordering by multiple fields then do it client side, it's the only solution

@bkstorm
Copy link

bkstorm commented May 28, 2019

Or write a raw query, then use prisma.$fragment to get the type of data you need.

@juliosampaio
Copy link

@bkstorm could you provide us an example please?

@alan345
Copy link

alan345 commented Oct 10, 2019

Is this feature will never be launched?

@cesarve77
Copy link

it is a must to have feature, waiting almost 3 years?

@alan345
Copy link

alan345 commented Nov 19, 2019

Prisma team, Are you working on this feature for Prisma V2?

@homerjam
Copy link

homerjam commented Dec 6, 2019

Or write a raw query, then use prisma.$fragment to get the type of data you need.

@bkstorm Do you have an example of this please?

@bkstorm
Copy link

bkstorm commented Dec 11, 2019

Or write a raw query, then use prisma.$fragment to get the type of data you need.

@bkstorm Do you have an example of this please?

I don't use Prisma 1 any more due to it lacks a lot of features, like this one, but I will try to create an example code for you.

@AdamErwee
Copy link

Or write a raw query, then use prisma.$fragment to get the type of data you need.

@bkstorm Do you have an example of this please?

I don't use Prisma 1 any more due to it lacks a lot of features, like this one, but I will try to create an example code for you.

Sorry, was just wondering if you ever got around an example for this?

@janpio janpio closed this as completed Sep 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet