Review the ticket and the commits. You would have to monkey patch the Arel visitor as I did in the fix commits and then use an Arel sql literal wrapper as the comment/tests show.
> *duh* I should have searched github, not just google. However, I
> wasn't sure what kind of problem I was having. Now at least, I know it
> is in rails-sqlserver-adapter.
> I see that is has been addressed, in 3.1.5. However, I am on 3.0.19
> (since I am using rails 3.0, I am upgrading from 2.3 and didn't want
> to upgrade directly to 3.2). Can the fix be applied to 3.0.19?
> Also, if I define the order like this:
> Arel::Nodes::Ordering.new(Arel.sql('CASE WHEN ended_on IS NULL THEN 1
> ELSE 0 END'))
> it works... however, this is also valid sql and doesn't work:
> Arel::Nodes::Ordering.new(Arel.sql('CASE WHEN ended_on IS NULL THEN 1
> ELSE 0 END, ended_on DESC'))
> This last ordering spits out the following error:
> SELECT [addresses].* FROM [addresses] ORDER BY CASE WHEN ended_on IS
> NULL THEN 1 ELSE 0 END, ended_on DESC ASC
> Seems that it throws and extra ASC in the for good measure, which
> bungles the whole thing... how to I prevent it from doing that? I want
> to do this:
> has_many :addresses, :order =>
> Arel::Nodes::Ordering.new(Arel.sql('CASE WHEN ended_on IS NULL THEN 1
> ELSE 0 END, ended_on DESC'))
> Is there a workaround?
> I appreciate your help!
> - Niels
> On Mar 7, 4:19 pm, Ken Collins <k...@metaskills.net> wrote:
>> Have you searched on the Github issues for things like "order"? This ticket comes to the top and seems related.
>> https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pul...
>> It explains about how the adapter/visitor has to work with orders and the need for using an Arel sql literal. Because of that and the various tickets, we have an extensive order test too.
>> https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blo...
> --
> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> To post to this group, send email to rails-sqlserver-adapter@googlegroups.com.
> To unsubscribe from this group, send email to rails-sqlserver-adapter+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rails-sqlserver-adapter?hl=en.