You could also put a method like this in your Request model

def Request.sql_tag_color_order
  '(CASE requests.tag_color WHEN 'red' THEN 1 WHEN 'yellow' THEN 2
WHEN 'green' THEN 3 ELSE 4 END)'
end

Then change the line in your Customer model to
has_many :requests, :order => "priority,
#{Request.sql_tag_color_order}"

That way when you want to order requests in another part of your
application you can use Request.sql_tag_color_order instead of having
to repeat the transformation from text to something order.

HTH

Neal L wrote:
> Hi all,
>
> I'm working on a help system that lets users assign a "tag color" to
> their requests in addition to assigning the usual "high, medium, low"
> priority.  My question is whether it's possible to do a sort based on
> the tag color.  Valid colors are green, yellow, orange, and red, and
> these are stored as strings in the database.
>
> I'd like to use something like:
>
> # Customer Model
> has_many :requests, :order => priority, tag_color
>
> Is it possible to add a sort based on these string values?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to