Most questions about advanced ordering involve a few prioritized fields, but here’s a different problem.
I have a series of projects ordered by title, and these projects are assigned to individuals in the company. I want to be able to have each individual’s projects float to the top for that individual.
This is not a request to order by assigned_individual then job_title (because this would mess up the ordering of all projects that aren’t mine). This is a request to have records still ordered principally by job_title but to have an override such that records with, let’s say, assigned_individual_id = 3 are shown first.
Not hard, you just have to slip a CASE into your ORDER BY to manually push the rows of interest to the top, something like this:
where, of course,
idis the user that you want on top. If this is done inside one of M’s methods then you won’t need to usesendto get around the protectedness ofsanitize_sql.This technique can easily be extended to push multiple users to the top if that’s needed.