-
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
Storing state names in the database #211
Comments
Hey Isaac, I think you could achieve this with the current setup - am I right that all you're looking for is a level of indirection on your state names? You could use constants for that: class MyStatemachine
include Statesman::Machine
CREATED = :a
SUBSEQUENT = :b
state CREATED, initial: true
state SUBSEQUENT
transition from: CREATED, to: [SUBSEQUENT]
# etc.
end The above should give the same support as allowing you to assign a value to each state name. However, we could go further and fully integrate support for this into the gem, probably with a setting. I'm not sure exactly what that would look like, but I don't see why it would need to be breaking. |
Hi Grey, Thanks for getting back to me! Using constants does solve one of my issues (making it easy to rename states without running a migration) but I have a few reservations about using them:
Cheers, |
Hi @isaac (jealous of the username!). I think the real difficulty here is the fact that Statesman is designed to work with a static set of states, defined in the source and not changed at run-time. Do you also want to store the valid set of transitions in your database? If not, how do you define what valid transitions exist? On your second point, I'm not sure where the constraints are imposed - the value of a constant can be anything, and Statesman supports any Ruby string/symbol for state names, so you can name your states with emojis if you wish ( Isaac |
Hi,
Statesman looks like a great gem and I would love to use it, but there is one thing holding me back: I would like to get my state names from a "states" database table. I would then like to store the primary key from the table as the value of the state in the transitions table. I would store the state names as strings (not symbols). There are a few reasons for this:
https://github.com/state-machines/state_machines - this gem enables this behaviour with the following syntax
state :active, :value => 1
Would you consider implementing/supporting a change like this?
Can anyone think of another way to achieve this?
Cheers,
Isaac
The text was updated successfully, but these errors were encountered: