Laravel-mongodb: OrderBy by sub Relationship with paginate

Created on 30 May 2019  路  3Comments  路  Source: jenssegers/laravel-mongodb

Hello !

How I can achieve an orderBy query like:

Resource::orderBy('field from relationship of resource')->paginate(X);

I tested something like orderBy('nameofrelationship.field to order') but It does not work.

I also tried:
Resource::with('nameofrelationship')->orderBy('nameofrelationship.field to order')->paginate(X);

I don't want to use the sort method of Collection ! I need to order my items in the mongodb query because I use a pagination !

Thanks a lot !

question

Most helpful comment

Hi!

I'm on the same problem, anyone have a solution? I thought in use aggregate to do the trick, but that looks like a bazooka to killing an ant.

All 3 comments

Hi!

I'm on the same problem, anyone have a solution? I thought in use aggregate to do the trick, but that looks like a bazooka to killing an ant.

Hi!

I'm on the same problem, anyone have a solution?

Hello,

Use mongodb raw query, this is not a simple SQL.

Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

naveedyasin picture naveedyasin  路  3Comments

phuocduy1988 picture phuocduy1988  路  3Comments

HassanIbrahim picture HassanIbrahim  路  3Comments

YSimple picture YSimple  路  3Comments

tomartailored picture tomartailored  路  3Comments