这个问题是真正打算由AASM gem 开发人员来回答的。
我在我的 rails 应用程序模型 ( Mongoid )中使用AASM gem。我知道您会为每个定义的状态自动生成范围。例如,拥有这个...
class Order
include Mongoid::Document
include Mongoid::Timestamps
include AASM
field :aasm_state
aasm do
state :pending, :initial => true
state :received
event :receive do
transitions :from => :pending, :to => :received
end
end
end
...允许我这样做:Order.pending和Order.received。
我的问题很简单,您是否还生成范围来获得给定状态的补码?类似于:Order.not_pending以获取状态不同于“待处理”的订单?
我知道很容易建立自己的范围来获得它,就像这样......
scope :not_pending, ->{ ne(aasm_state: "pending") }
...但我想确保你没有定义它,因为如果你这样做,我宁愿使用你的范围而不是我自己的。