I have the following query that does not work in rails s in a specific controller. This does not fail in rails c .
Post.includes(:user).find(:all, :limit => 10, :order => 'users.display_name ASC')
In the console, it returns the correct data. On the server, I get this error
ActiveRecord::StatementInvalid: PGError: ERROR: column posts.users.display_name does not exist LINE 1: ...s_count" AS t0_r7, "posts"."popularity" AS t0_r8, "posts"."u... ^
The request is long and Iโll just include some relevant snippets
: SELECT "posts"."id" AS t0_r0, "posts"."post_content" AS t0_r1, ... "posts"."popularity" AS t0_r8, "posts"."users.display_name" AS t0_r9, "posts"."subtopics.name" AS t0_r10, "posts"."categories.category_name" AS t0_r11 ... FROM "posts" LEFT OUTER JOIN "users" ON "users"."id" = "posts"."user_id" ORDER BY users.display_name ASC LIMIT 10
In the controller, the request generates 3 additional terms. The request calls them t0_r9, t0_r10 and t0_r11. It seems that AR adds this because I refer to these specific columns in the representation of this controller action. I do not understand why this would do this, especially since the purpose of using includes .
source share