Ruby on rails 获取Rails中AASM Gem生成的作用域的补码
这个问题实际上是要由aasmgem开发人员来回答的 我在rails应用程序模型中使用AASM gem(Mongoid)。我知道您会自动为每个已定义的状态生成作用域。例如,有这个Ruby on rails 获取Rails中AASM Gem生成的作用域的补码,ruby-on-rails,mongoid,aasm,Ruby On Rails,Mongoid,Aasm,这个问题实际上是要由aasmgem开发人员来回答的 我在rails应用程序模型中使用AASM gem(Mongoid)。我知道您会自动为每个已定义的状态生成作用域。例如,有这个 class Order include Mongoid::Document include Mongoid::Timestamps include AASM field :aasm_state aasm do state :pending, :initial => true
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以获取状态不同于“pending”的订单
我知道很容易建立自己的范围来获得它,就像这样
scope :not_pending, ->{ ne(aasm_state: "pending") }
…但我想确定你没有定义它,因为如果你定义了,我宁愿使用你的范围而不是我自己的范围 不,AASM没有提供相反的范围。我们已经考虑过了,但最后还是决定反对,因为这样做不会给范围空间带来太多的负担。谢谢你的快速回答,兄弟!。