Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to order associated columns case insensitive

I'm trying to order all my projects by their customer company names, but I get this error: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "customers" LINE 1: ... WHERE "projects"."archived" = $1 ORDER BY LOWER(customers.... ^ : SELECT "projects".* FROM "projects" WHERE "projects"."archived" = $1 ORDER BY LOWER(customers.company) ASC.

This is how I tried it so far:

projects = Project.includes(:customer).order("LOWER(customers.company) ASC")

If I leave out LOWER(…) everything works fine.

like image 957
Slevin Avatar asked Jan 20 '26 15:01

Slevin


1 Answers

You need to write it using references.

Project.includes(:customer)
       .order("LOWER(customers.company) ASC")
       .references(:customers)
like image 152
Arup Rakshit Avatar answered Jan 23 '26 05:01

Arup Rakshit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!