第一个问题
ScenicArea.order("hot_spot desc").order("id asc") 生成的查询是 SELECT scenic_areas
.* FROM scenic_areas
ORDER BY hot_spot desc, id asc
ScenicArea.order("hot_spot desc, id asc") 生成的查询是。SELECT scenic_areas
.* FROM scenic_areas
ORDER BY hot_spot desc, id asc
为什么是相同的 连续调用 order 后面的不应该覆盖前面的吗
第二个问题 post"/scenic_area/list" do check_params_sign @scenic_areas = ScenicArea.publish if params[:city_id].present? @scenic_areas = ScenicArea.by_city_id(params[:city_id]) @distance = 5000 else @distance = 50 end if params[:order].present? && params[:order].to_s == 'hot' @scenic_areas = @scenic_areas.order("hot_spot desc") else @scenic_areas = @scenic_areas.order(:distance) end if (params[:latitude].present? and params[:longitude].present?) @scenic_areas = @scenic_areas.near([params[:latitude],params[:longitude]],@distance.to_i, units: :km) end @scenic_areas = @scenic_areas.paginate(:per_page=>per_page,:page=>page) present({"code": 0,"msg": "ok", "data": {"scenic_areas": @scenic_areas.collect{|c|c.as_json(false)},"current_page": page,"total_pages": @scenic_areas.total_pages}}) end 这样写返回的结果是我想要的按照热度排序的结果 post"/scenic_area/list" do check_params_sign @scenic_areas = ScenicArea.publish if params[:city_id].present? @scenic_areas = ScenicArea.by_city_id(params[:city_id]) @distance = 5000 else @distance = 50 end if (params[:latitude].present? and params[:longitude].present?) @scenic_areas = @scenic_areas.near([params[:latitude],params[:longitude]],@distance.to_i, units: :km) end if params[:order].present? && params[:order].to_s == 'hot' @scenic_areas = @scenic_areas.order("hot_spot desc") else @scenic_areas = @scenic_areas.order(:distance) end @scenic_areas = @scenic_areas.paginate(:per_page=>per_page,:page=>page) present({"code": 0,"msg": "ok", "data": {"scenic_areas": @scenic_areas.collect{|c|c.as_json(false)},"current_page": page,"total_pages": @scenic_areas.total_pages}}) end 这样把 order 排序放在后面反而不会按照热度排序 返回的是按照距离排序的结果 这两个问题都不是很清楚 希望有懂的帮我解答一下