raoul2000 / yii2-workflow

A simple workflow engine for Yii2
BSD 3-Clause "New" or "Revised" License
171 stars 48 forks source link

Use foreign key column as attribute #22

Closed gdiazderadaa closed 8 years ago

gdiazderadaa commented 8 years ago

Hi there! I was wondering if yii2-workflow supports foregin key column as workfow attribute, cause I'm using a related model to manage statuses dynamically, so instead 'status' col would be 'status_id'

Thanks!

raoul2000 commented 8 years ago

hi, you can indeed configure the name of the attribute and replace the default 'status' with 'status_id'. This can be done by using the statusAttribute property in the SimpleWorkflowBehavior class.

hope this helps !

gdiazderadaa commented 8 years ago

Hi, thanks for the answer. Do I need to use then the status_id in the workflow class as well? Cause it'd look less readable...

alladas commented 8 years ago

Hi @gdiazderadaa , "statusAttribute" is global. Once set in the behaviors of your model, you are not going to need it in the workflow.

maoneid commented 8 years ago

i want to update status. but it is still PostWorkflow/publish on status value during update to database. how to covert status to publish before save to database?

Thanks.

maoneid commented 8 years ago

should i use status id converter interface?

raoul2000 commented 8 years ago

Hi @maoneid, yes, if you want to handle the status value saved in the db, you should create a statusIdConverter class that implements the IStatusConverter interface and then initialize the statusConverter attribute of the SimpleWorkflowBehavior class with it.

You can also use the provided StatusConverter class which is a map based converter implementation (you can find an example usage in the unit test section).

ciao