Fix unqualified column references.

Fix various places to avoid unqualified column references to prevent any
potential ambiguous column errors.
This commit is contained in:
evazion
2022-03-01 17:48:16 -06:00
parent 036341d8ba
commit ad3f3fdce3
8 changed files with 15 additions and 15 deletions

View File

@@ -65,7 +65,7 @@ class Comment < ApplicationRecord
end
def update_last_commented_at_on_destroy
other_comments = Comment.where("post_id = ? and id <> ?", post_id, id).order("id DESC")
other_comments = Comment.where("post_id = ? and id <> ?", post_id, id).order(id: :desc)
if other_comments.count == 0
Post.where(:id => post_id).update_all(:last_commented_at => nil)
else

View File

@@ -127,7 +127,7 @@ class ForumPost < ApplicationRecord
end
def update_topic_updated_at_on_delete
max = ForumPost.where(:topic_id => topic.id, :is_deleted => false).order("updated_at desc").first
max = ForumPost.where(topic_id: topic.id, is_deleted: false).order(updated_at: :desc).first
if max
ForumTopic.where(:id => topic.id).update_all(["updated_at = ?, updater_id = ?", max.updated_at, max.updater_id])
end
@@ -140,7 +140,7 @@ class ForumPost < ApplicationRecord
end
def update_topic_updated_at_on_destroy
max = ForumPost.where(:topic_id => topic.id, :is_deleted => false).order("updated_at desc").first
max = ForumPost.where(topic_id: topic.id, is_deleted: false).order(updated_at: :desc).first
if max
ForumTopic.where(:id => topic.id).update_all(["response_count = response_count - 1, updated_at = ?, updater_id = ?", max.updated_at, max.updater_id])
else

View File

@@ -3,7 +3,7 @@
class NewsUpdate < ApplicationRecord
belongs_to :creator, class_name: "User"
belongs_to_updater
scope :recent, -> {where("created_at >= ?", 2.weeks.ago).order("created_at desc").limit(5)}
scope :recent, -> {where("created_at >= ?", 2.weeks.ago).order(created_at: :desc).limit(5)}
def self.visible(user)
if user.is_admin?

View File

@@ -983,11 +983,11 @@ class Post < ApplicationRecord
end
def random_up(key)
where("md5 < ?", key).reorder("md5 desc").first
where("md5 < ?", key).reorder(md5: :desc).first
end
def random_down(key)
where("md5 >= ?", key).reorder("md5 asc").first
where("md5 >= ?", key).reorder(md5: :asc).first
end
def sample(query, sample_size)

View File

@@ -90,7 +90,7 @@ class SavedSearch < ApplicationRecord
def labels_for(user_id)
SavedSearch
.where(user_id: user_id)
.order("label")
.order(label: :asc)
.pluck(Arel.sql("distinct unnest(labels) as label"))
end
end

View File

@@ -295,11 +295,11 @@ class Tag < ApplicationRecord
case params[:order]
when "name"
q = q.order("name")
q = q.order(name: :asc)
when "date"
q = q.order("id desc")
q = q.order(id: :desc)
when "count"
q = q.order("post_count desc")
q = q.order(post_count: :desc)
when "similarity"
q = q.order_similarity(params[:fuzzy_name_matches]) if params[:fuzzy_name_matches].present?
else

View File

@@ -657,13 +657,13 @@ class User < ApplicationRecord
case params[:order]
when "name"
q = q.order("name")
q = q.order(name: :asc)
when "post_upload_count"
q = q.order("post_upload_count desc")
q = q.order(post_upload_count: :desc)
when "note_count"
q = q.order("note_update_count desc")
q = q.order(note_update_count: :desc)
when "post_update_count"
q = q.order("post_update_count desc")
q = q.order(post_update_count: :desc)
else
q = q.apply_default_order(params)
end

View File

@@ -94,7 +94,7 @@ class WikiPage < ApplicationRecord
case params[:order]
when "title"
q = q.order("title")
q = q.order(title: :asc)
when "post_count"
q = q.includes(:tag).order("tags.post_count desc nulls last").references(:tags)
else