geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

workflow_state persistence on unsaved AR models #165

Closed gamov closed 2 years ago

gamov commented 8 years ago

Triggering a state change on a unsaved AR model raises:

ActiveRecord::ActiveRecordError: can not update on a new record object
/activerecord-3.2.22/lib/active_record/persistence.rb:195:in `update_column'
/workflow-1.2.0/lib/workflow/adapters/active_record.rb:20:in `persist_workflow_state'
/workflow-1.2.0/lib/workflow.rb:124:in `process_event!'
/workflow-1.2.0/lib/workflow.rb:64:in `block (4 levels) in assign_workflow'

I think it should only be updated in memory if new_record? Ref: https://github.com/geekq/workflow/blob/master/lib/workflow/adapters/active_record.rb#L17