Named scope and order overriding


#1

Hi everyone,
My question is: How do I override named_scope settings rather than merge
with them?

Say I have a model Vehicles
It has a named_scope called red_trucks that sets some filters and an
order by id.

Now lets say I want to find the unique values for an attribute.
So I might go

Vehicles.red_trucks.find(:all, “SELECT DISTINCT model_year”)
This breaks in postgres with the following error
“for SELECT DISTINCT, ORDER BY expressions must appear in select list”

ok, so lets add the model_year
Vehicles.red_trucks.find(:all, “SELECT DISTINCT model_year”,
:order=>“model_year”)

This still gives me the same error because the ‘order by id’ is still
there from the red_trucks name_scope. How do I override the order so it
because “model_year” instead of “model_year,id”?

Or is there a better way of doing this?


#2

aa aa wrote:
small typo

This still gives me the same error because the ‘order by id’ is still
there from the red_trucks name_scope. How do I override the order so it
because “model_year” instead of “model_year,id”?
should be
This still gives me the same error because the ‘order by id’ is still
there from the red_trucks name_scope. How do I override the order so it
is “model_year” instead of “model_year,id”?