If you have more than 9 tables to join, a ActiveRecord::StatementInvalid error will occur, that's because the but in the regular expression that detect aliases.
in file sqlserver_adapter
line 485:
if sql =~ /#{Regexp.escape(order_by_column)} AS (t\d_r\d\d?)/
it should be :
if sql =~ /#{Regexp.escape(order_by_column)} AS (t\d\d?_r\d\d?)/
or :
if sql =~ /#{Regexp.escape(order_by_column)} AS (t\d+_r\d+)/