-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No easy way to find previous state #263
Comments
I am currently using
I am not aware of a simpler way to do this, or avoiding the DB hit to transitions table. |
I'm not a statesman expert, but it looks like we have some very similar code in our application: previous_state = model.transitions.order(:sort_key).reject(&:most_recent?).last.to_state I'm not sure why such a helper method does not exist (but I think you're right, it would require a separate DB call to figure out the answer). |
|
This issue is old, but I'm just starting to use Statesman particularly because of it's transition history and I ran into the lack of a 'previous state' feature. I don't think any of these proposals solves the issues thoroughly. Issue 1To the phrasing by @stevebissett, which I think is the most complete for this purpose, Also - though this is a minor point on this one phrasing - you'll also get a I'd suggest the following code to fix this issue.
-- Issue 2If the code defining the initial state changes, any models that have only one transition recorded will be return the incorrect result. eg. On June 1st code defines:
We record our record moving from state However on June 15th we refactor our state machine to read
Now Unfortunately, I don't see a way to get around this without persisting the |
Hey @ManickYoj, thanks for your thorough comment. Summarising my understanding of the comments above and on #348
I will try find some time in the coming days/weeks to give this some further thought (unfortunately don't have much time to dedicate to Statesman) but my initial thoughts are that adding a It seems like this is a quite common feature that people would find useful and after that we can explore improvements. |
I think you captured it all, @thom-oman . FWIW, my team decided to work with aasm and the aasm_history gem instead in large part because of Statesman's currently limited ability to accurately and easily determine the previous state. That is to say, I don't particularly have a dog in this fight anymore, but can confirm that it's a common feature that people would find useful 😄 |
Thanks for a great approach to a state machine.
It seems like there is no easy method of finding the previous state for a state machine. I would have thought this would be something very common, so perhaps I am missing something?
The
to_state
is captured in the DB for a transition, and I thought thefrom_state
would either be saved in the DB, or deduced from transition information.Is there a way of finding this easily? Or may you explain the reason this was excluded if it was done intentionally?
The text was updated successfully, but these errors were encountered: