Fix #4869: "Random" button raises exception when viewing ordfav.
Fix exception during https://danbooru.donmai.us/posts/random?tags=ordfav:nonamethanks Before we were doing a query like this: SELECT "posts".* FROM "posts" INNER JOIN "favorites" ON "favorites"."post_id" = "posts"."id" WHERE (favorites.user_id % 100 = 64 AND favorites.user_id = 52664) AND "posts"."id" = 343894 ORDER BY favorites.id DESC, posts.id DESC, ID=343894 DESC but `ID=? DESC` is ambiguous during an ordfav: search because of the join on the favorites table. The fix is to qualify the reference as `posts.id`.
This commit is contained in:
@@ -505,7 +505,7 @@ module Searchable
|
||||
def find_ordered(ids)
|
||||
order_clause = []
|
||||
ids.each do |id|
|
||||
order_clause << sanitize_sql_array(["ID=? DESC", id])
|
||||
order_clause << sanitize_sql_array(["#{qualified_column_for(:id)} = ? DESC", id])
|
||||
end
|
||||
where(id: ids).order(Arel.sql(order_clause.join(', ')))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user