We're getting this beast:
ActiveRecord::StatementInvalid: PG::Error: ERROR: non-integer constant in ORDER BYLINE 1: ...= "orders"."id" WHERE "orders"."user_id" = 11 ORDER BY '--- ^: SELECT "orders"."id" AS t0_r0, "orders"."user_id" AS t0_r1, "orders"."confirmed" AS t0_r2, "orders"."fulfilled" AS t0_r3, "orders"."phone" AS t0_r4, "orders"."email" AS t0_r5, "orders"."extra" AS t0_r6, "orders"."created_at" AS t0_r7, "orders"."updated_at" AS t0_r8, "orders"."instructions" AS t0_r9, "users"."id" AS t1_r0, "users"."email" AS t1_r1, "users"."encrypted_password" AS t1_r2, "users"."reset_password_token" AS t1_r3, "users"."reset_password_sent_at" AS t1_r4, "users"."remember_created_at" AS t1_r5, "users"."sign_in_count" AS t1_r6, "users"."current_sign_in_at" AS t1_r7, "users"."last_sign_in_at" AS t1_r8, "users"."current_sign_in_ip" AS t1_r9, "users"."last_sign_in_ip" AS t1_r10, "users"."created_at" AS t1_r11, "users"."updated_at" AS t1_r12, "users"."phone" AS t1_r13, "users"."first_name" AS t1_r14, "users"."last_name" AS t1_r15, "users"."pcv_id" AS t1_r16, "users"."country_id" AS t1_r17, "users"."role" AS t1_r18, "users"."city" AS t1_r19, "requests"."id" AS t2_r0, "requests"."supply_id" AS t2_r1, "requests"."dose" AS t2_r2, "requests"."quantity" AS t2_r3, "requests"."created_at" AS t2_r4, "requests"."updated_at" AS t2_r5, "requests"."order_id" AS t2_r6 FROM "orders" LEFT OUTER JOIN "users" ON "users"."id" = "orders"."user_id" LEFT OUTER JOIN "requests" ON "requests"."order_id" = "orders"."id" WHERE "orders"."user_id" = 11 ORDER BY '--- :orders: created_at DESC'
from calling User#accesible_orders. It looks to be some bad interaction between the two default scopes on orders.