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.
You need to write it using references.
Project.includes(:customer)
.order("LOWER(customers.company) ASC")
.references(:customers)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With