Sql 铁路4:为什么是';在DESC和x27处创建;追加 ;自动地?如何删除它?

Sql 铁路4:为什么是';在DESC和x27处创建;追加 ;自动地?如何删除它?,sql,ruby-on-rails,ruby,ruby-on-rails-4,Sql,Ruby On Rails,Ruby,Ruby On Rails 4,虽然我想按文章的平均评分排序记录,但当我选中development.log时,order by created\u at DESC会自动追加 为什么附加这个条件?我怎样才能删除它 .schema文章 CREATE TABLE "articles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "content" text(400), "user_id" integer, "created_at" datetime, "updated_at"

虽然我想按文章的平均评分排序记录,但当我选中
development.log
时,
order by created\u at DESC
会自动追加

为什么附加这个条件?我怎样才能删除它

.schema文章

CREATE TABLE "articles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "content" text(400), "user_id" integer, "created_at" datetime, "updated_at" datetime,"category_id" integer, "rating" real);
CREATE INDEX "index_articles_on_user_id_and_created_at" ON "articles" ("user_id", "created_at");
\model\category.rb

class Category < ActiveRecord::Base
    has_many :articles
    ...
end

如果您想要
default\u范围
,但不想将其单独用于特定查询,请在查询中使用
unscoped
。例如:

Article.unscoped.select('*, AVG(rating) AS avg_rate').group(:category_id).order('avg_rate DESC')

请您提供所有文章.rb好吗?谢谢您的评论,@maxd。当我再次检查article.rb时,我发现
默认范围->{order('created_at DESC')}
存在。lol只是想问你是否有默认范围,我猜你找到了,这是我讨厌默认范围的原因之一
class CategoriesController < ApplicationController

  def index
    @articles = Article.select('*, AVG(rating) AS avg_rate').group(:category_id).order('avg_rate DESC')
  end

    ...

end
Processing by CategoriesController#index as HTML
  [1m[36mArticle Load (1.0ms)[0m  [1mSELECT *, AVG(rating) AS avg_rate FROM "articles" GROUP BY category_id ORDER BY created_at DESC, avg_rate DESC[0m
....
Article.unscoped.select('*, AVG(rating) AS avg_rate').group(:category_id).order('avg_rate DESC')