绕过应用于Relation的范围参数

时间:2014-05-20 16:20:55

标签: ruby-on-rails ruby-on-rails-4 rails-activerecord

我有以下定义:

class Category
  has_many :questions, -> { order(weekday: :asc) }
end

是否可以像下面那样进行查询并故意忽略上面的lambda?

Category.first.questions

1 个答案:

答案 0 :(得分:1)

Category.first.questions.unscope(:order)
Category.first.questions.except(:order)

请参阅http://apidock.com/rails/ActiveRecord/QueryMethods/unscopehttp://apidock.com/rails/ActiveRecord/SpawnMethods/except