+ elsif attr.match /^([a-z][_a-z0-9]+)\.([a-z][_a-z0-9]+)$/ and
+ ['asc','desc'].index(direction.downcase) and
+ ActiveRecord::Base.connection.tables.include?($1) and
+ $1.classify.constantize.columns.collect(&:name).index($2)
+ # $1 in the above checks references the first match from the regular expression, which is expected to be the database table name
+ # $2 is of course the actual database column name
+ @orders << "#{attr} #{direction.downcase}"