Rails 4: Using PostgreSQL function in order causes error in query due to the includes table not being joined
问题 I found an odd problem with Rails 4 Active Record queries where the includes table is not joined if I use a PostgreSQL function in the order. This same query works fine if I remove the PostgreSQL function. This works fine... Widget.includes(:sprocket).order("sprockets.name").all This fails because the includes relationship is not joined... Widget.includes(:sprocket).order("lower(sprockets.name)").all Notice the only thing different is the lower(sprockets.name). I know I can add .references