我希望将附加查询链接到模型中的范围。范围在关注中定义。
module Companyable
extend ActiveSupport::Concern
included do
scope :for_company, ->(id) {
where(:company_id => id)
}
end
end
class Order < ActiveRecord::Base
include Companyable
# I'd like to be able to do something like this:
scope :for_company, ->(id) {
super(id).where.not(:status => 'cancelled')
}
end
Run Code Online (Sandbox Code Playgroud)
然而,这可以理解地抛出一个 NameError: undefined method 'for_company' for class 'Order'