raoul2000 / yii2-workflow

A simple workflow engine for Yii2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Model inheritance

ferllings opened this issue · comments

Hello,
First of all, thanks for your awesome package, I've been using it since Yii1.

I have few similar models, named Archive1, Archive2...

class Archive1 extends  Archive
{
	public static function tableName()
	{
		return '{{%archive1}}';
	}
...

I'm using a common base for each named Archive, where I've added the workflow behaviour.

class Archive extends ActiveRecord
{
	public function behaviors()
	{
		return [
			[
				'class' => SimpleWorkflowBehavior::className(),
                'defaultWorkflowId'        => 'Archive',
			]
		];   
	}

My Workflow looks like:

class ArchiveWorkflow implements IWorkflowDefinitionProvider
{
	public function getDefinition() {
		return [
			'initialStatusId' => 'draft',
			'status' => [
				'draft' => [
					'transition'=>['submitted'],
					'label'=>'Draft',
				],
				'submitted' => [
					'transition'=>[],
					'label'=>'Submitted',
				]
			]
		];
	}
}

When I try to save the model...

$model = new Archive1;
$model->status = 'draft';
$model->save();

...I get the following error:

Invalid Configuration – yii\base\InvalidConfigException
The table does not exist: {{%archive}}

Looks like the workflow is trying to use the workflow name 'Archive' as table name, instead of the model name.

Is there a way to override that?

Thanks for your help.

The issue was due to the fact that both my Workflow id and my parent class name was 'Archive' and all the files are in the same model folder.

I fixed it my moving my workflow file into app/models/workflows/ folder