Erwin
2012-Jun-06 13:04 UTC
how to do a Model.order(:name) using a :case_sensitive => false ?
this option is available in validation.. is there any equivalent when doing a query or should it be SQL dependent ( coded in the model ) ? thanks for feedback -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2012-Jun-06 20:08 UTC
Re: how to do a Model.order(:name) using a :case_sensitive => false ?
Kad Kerforn wrote in post #1063333:> this option is available in validation.. > is there any equivalent when doing a query or should it be SQL > dependent ( coded in the model ) ? > > thanks for feedbackorders = Order.order(''lower(name)'') Order Load (0.5ms) SELECT "orders".* FROM "orders" ORDER BY lower(name) -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2012-Jun-06 20:16 UTC
Re: how to do a Model.order(:name) using a :case_sensitive => false ?
Robert Walker wrote in post #1063410:> orders = Order.order(''lower(name)'') > Order Load (0.5ms) SELECT "orders".* FROM "orders" ORDER BY > lower(name)Keep in mind that the above will force the database to perform a sequential scan of the table even if the column you''re ordering by is indexed. Which means that if you have performance issues you may need to create a case-insensitive index on the column. I''ll leave that as an exercise for you on how to set that up in whatever database you are using. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Erwin
2012-Jun-07 10:23 UTC
Re: how to do a Model.order(:name) using a :case_sensitive => false ?
Ok thanks a lot .. in the meantime , I modified my record design , adding a ds_name string which is the lower(name) written upon create, so I can order on it directly... as it''s for ''tag'' records, I''ll not have billion of records .. according to your feedback I can create a case-insensitive index on the column.. even better On Jun 6, 10:16 pm, Robert Walker <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Robert Walker wrote in post #1063410: > > > orders = Order.order(''lower(name)'') > > Order Load (0.5ms) SELECT "orders".* FROM "orders" ORDER BY > > lower(name) > > Keep in mind that the above will force the database to perform a > sequential scan of the table even if the column you''re ordering by is > indexed. Which means that if you have performance issues you may need to > create a case-insensitive index on the column. I''ll leave that as an > exercise for you on how to set that up in whatever database you are > using. > > -- > Posted viahttp://www.ruby-forum.com/.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.