#2217 fix ambiguous table references
This commit is contained in:
@@ -228,28 +228,28 @@ class PostQueryBuilder
|
|||||||
|
|
||||||
if q[:commenter_ids]
|
if q[:commenter_ids]
|
||||||
q[:commenter_ids].each do |commenter_id|
|
q[:commenter_ids].each do |commenter_id|
|
||||||
relation = relation.where(:id => Comment.where("creator_id = ?", commenter_id).select("post_id").uniq)
|
relation = relation.where("posts.id IN (?)", Comment.where("creator_id = ?", commenter_id).select("post_id").uniq)
|
||||||
end
|
end
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:noter_ids]
|
if q[:noter_ids]
|
||||||
q[:noter_ids].each do |noter_id|
|
q[:noter_ids].each do |noter_id|
|
||||||
relation = relation.where(:id => Note.where("creator_id = ?", noter_id).select("post_id").uniq)
|
relation = relation.where("posts.id IN (?)", Note.where("creator_id = ?", noter_id).select("post_id").uniq)
|
||||||
end
|
end
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:note_updater_ids]
|
if q[:note_updater_ids]
|
||||||
q[:note_updater_ids].each do |note_updater_id|
|
q[:note_updater_ids].each do |note_updater_id|
|
||||||
relation = relation.where(:id => NoteVersion.where("updater_id = ?", note_updater_id).select("post_id").uniq)
|
relation = relation.where("posts.id IN (?)", NoteVersion.where("updater_id = ?", note_updater_id).select("post_id").uniq)
|
||||||
end
|
end
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:artcomm_ids]
|
if q[:artcomm_ids]
|
||||||
q[:artcomm_ids].each do |artcomm_id|
|
q[:artcomm_ids].each do |artcomm_id|
|
||||||
relation = relation.where(:id => ArtistCommentaryVersion.where("updater_id = ?", artcomm_id).select("post_id").uniq)
|
relation = relation.where("posts.id IN (?)", ArtistCommentaryVersion.where("updater_id = ?", artcomm_id).select("post_id").uniq)
|
||||||
end
|
end
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
@@ -314,7 +314,8 @@ class PostQueryBuilder
|
|||||||
|
|
||||||
if q[:ordfav].present?
|
if q[:ordfav].present?
|
||||||
user_id = q[:ordfav].to_i
|
user_id = q[:ordfav].to_i
|
||||||
relation = relation.joins(:favorites).where("favorites.user_id % 100 = ? and favorites.user_id = ?", user_id % 100, user_id).order("favorites.id DESC")
|
relation = relation.joins("INNER JOIN favorites ON favorites.post_id = posts.id")
|
||||||
|
relation = relation.where("favorites.user_id % 100 = ? and favorites.user_id = ?", user_id % 100, user_id).order("favorites.id DESC")
|
||||||
end
|
end
|
||||||
|
|
||||||
if q[:order] == "rank"
|
if q[:order] == "rank"
|
||||||
@@ -361,10 +362,12 @@ class PostQueryBuilder
|
|||||||
relation = relation.order("posts.last_noted_at ASC NULLS FIRST, posts.id DESC")
|
relation = relation.order("posts.last_noted_at ASC NULLS FIRST, posts.id DESC")
|
||||||
|
|
||||||
when "artcomm"
|
when "artcomm"
|
||||||
relation = relation.joins(:artist_commentary).order("artist_commentaries.updated_at DESC, posts.id DESC")
|
relation = relation.joins("INNER JOIN artist_commentaries ON artist_commentaries.post_id = posts.id")
|
||||||
|
relation = relation.order("artist_commentaries.updated_at DESC, posts.id DESC")
|
||||||
|
|
||||||
when "artcomm_asc"
|
when "artcomm_asc"
|
||||||
relation = relation.joins(:artist_commentary).order("artist_commentaries.updated_at ASC, posts.id DESC")
|
relation = relation.joins("INNER JOIN artist_commentaries ON artist_commentaries.post_id = posts.id")
|
||||||
|
relation = relation.order("artist_commentaries.updated_at ASC, posts.id DESC")
|
||||||
|
|
||||||
when "mpixels", "mpixels_desc"
|
when "mpixels", "mpixels_desc"
|
||||||
# Use "w*h/1000000", even though "w*h" would give the same result, so this can use
|
# Use "w*h/1000000", even though "w*h" would give the same result, so this can use
|
||||||
|
|||||||
Reference in New Issue
Block a user