Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple state machines in one model?

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?

like image 304
DGM Avatar asked Feb 24 '10 00:02

DGM


1 Answers

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.

like image 185
Darshan Avatar answered Nov 08 '22 08:11

Darshan