开发者

Multiple state machines in one model?

开发者 https://www.devze.com 2022-12-21 05:26 出处:网络
I have a model that represents a registration process, which needs to track the progression of开发者_开发技巧 several processes (background checks, interviews, information collection...).Each one can

I have a model that represents a registration process, which needs to track the progression of开发者_开发技巧 several processes (background checks, interviews, information collection...). Each one can be represented by a state machine, and then the overall state of the registration might depend on the state of the others.

Can aasm handle this? Any other ideas or design considerations?


Since this question comes up when you google multiple state machines in one model, it would be good to have an answer, although there is already an answer. Please try doing:

class Example < ActiveRecord::Base
 include AASM

    aasm :search, :column => :search do
    state :initialised, :initial => true
    ...
    end  
    aasm :sync, :column => :sync do
    state :unsynced, :initial => true
    ...
    end 
end

This will create two state machines based on two columns, search and sync.


Try this plugin, which you can use to even inherit from other state machines:

http://api.pluginaweek.org/state_machine/


If you need multiple statemachines in one model it's probably getting to big and it's time to split the model. So in your example you should add models for background checks, interviews, information collection...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号