Closed lwoodson closed 2 years ago
I agree, makes sense
Alright I'll put something together soon and get a PR back.
I'd say it makes sense to just use save!
. saving just the state
column without the rest of the changed attributes can create an invalid record in the database. i.e. one that would not be .valid?
after a find.
for example, if 'rejected' state requires 'reject_reason' to be set, the record in the db will not hold the reject_reason
if the object is not saved after transition.
Will be putting the PR together tonight or tomorrow night. I agree, @vitaly . I'll make sure that the entire changed state of the instance is saved and that its accomplished with a single DB call.
I think the whole change is quite simple:
def persist_workflow_state(new_value)
write_attribute(self.class.workflow_column, new_value)
save!
end
Yep, just haven't had time. Feel free to make the PR yourself, if you like. I'm pushing a big feature to (work) production on Tuesday, so I'm in grind mode.
I dont get it. I have just switched from aasm
gem to workflow, only to find out, it skips validations on transitions. "This way it is possible to deal with the validation and to save the pending changes to a record at some later point instead of the moment when transition occurs." Stupid explanation.
Currently when invoking transition event methods with ActiveRecord models, only the
workflow_state
column is updated in the database. Theupdated_at
column is not modified. This can be seen here:https://github.com/geekq/workflow/blob/master/lib/workflow/adapters/active_record.rb#L19
I would propose that the default behavior should be that
updated_at
should be updated when workflow state's change. If you agree @geekq, I can put together a pull request for this functionality.