{"issue":{"created_at":"2011-12-02T20:07:19Z","state":"closed","updated_at":"2011-12-05T14:23:51Z","comments":2,"user":{"gravatar_id":"b9c927e051202fc198e70659d9827d2f","id":338814,"url":"https://api.github.com/users/nathanl","login":"nathanl","avatar_url":"https://secure.gravatar.com/avatar/b9c927e051202fc198e70659d9827d2f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"I just stumbled on a behavior in state_machine that confuses me and I wondered if you could give some clarification.\r\n\r\nI had the following code on an ActiveRecord model:\r\n\r\n```ruby\r\nstate_machine :status, :initial => 'requested' do\r\n\r\n  event :approve do\r\n    transition :requested => :approved\r\n  end\r\n\r\n  # more events here...\r\nend\r\n```\r\n\r\nWhen I called `approve!`, I got `StateMachine::InvalidTransition: Cannot transition status via :approve from \"requested\" (Reason(s): Status cannot transition via \"approve\")`\r\n\r\nWhile puzzling over this, I idly changed `:initial => 'requested'` to `initial => :requested` and was surprised that it started working.\r\n\r\nI was calling this transition on a record that had been loaded from the database. Whether I had specified the initial status of the original object as a symbol or string, it was saved in the database as a string, and the new ActiveRecord object certainly pulled a string value out of the database. I don't see how it would \"know\" whether `status` on the original ActiveRecord object had been initialized with a symbol or string.\r\n\r\nIs this behavior by design or is it a bug? I'm not even sure how I would do this if I wanted to. :)","assignee":null,"id":2432441,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"number":144,"title":"Initial state cannot be a string?","closed_at":"2011-12-04T16:31:26Z","html_url":"https://github.com/pluginaweek/state_machine/issues/144","url":"https://api.github.com/repos/pluginaweek/state_machine/issues/144","milestone":null},"action":"created","comment":{"created_at":"2011-12-05T14:23:51Z","updated_at":"2011-12-05T14:23:51Z","user":{"gravatar_id":"b9c927e051202fc198e70659d9827d2f","id":338814,"url":"https://api.github.com/users/nathanl","login":"nathanl","avatar_url":"https://secure.gravatar.com/avatar/b9c927e051202fc198e70659d9827d2f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"Thanks for the detailed answer. Two follow-up questions:\r\n\r\n1) Would you take patch with a tiny bit of documentation on this? For instance, \"Note that state names are given as symbols. You may use strings, but you must be consistent: `:parked` is not the same state as `'parked'`.\r\n\r\n2) This would be much harder, but it would be lovely to get an error message if there are \"unconnected\" states. For example: \"Warning: there is no transition out of state `:parked`\" or \"Warning: there is no transition to state `:first_gear`\".","id":3017518,"url":"https://api.github.com/repos/pluginaweek/state_machine/issues/comments/3017518"}}