public function createRelations($definition = null)
    {
        $actions = array();
        $transitions = new ArrayObject();
        $sort = 1;
        foreach ($this->structure as $relationName => $relationTemplate) {
            $isAction = isset($relationTemplate['type']);
            $isUsers = ($relationName == 'users');
            $isGroups = ($relationName == 'groups');

            // Process actions on WorkflowDefinition from the template
            if ($isAction) {
                $action = $this->createAction($relationName, $relationTemplate, $definition);
                // add a sort value in!
                $action->Sort = $sort++;
                $action->write();

                $actions[$relationName] = $action;

                $newTransitions = $this->updateActionTransitions($relationTemplate, $action);
                foreach ($newTransitions as $t) {
                    $transitions->append($t);
                }
            }
            // Process users on WorkflowDefinition from the template
            if ($isUsers) {
                $this->createUsers($relationTemplate, $definition);
            }
            // Process groups on WorkflowDefinition from the template
            if ($isGroups) {
                $this->createGroups($relationTemplate, $definition);
            }
        }

        foreach ($transitions as $transition) {
            if (isset($actions[$transition->Target])) {
                $transition->NextActionID = $actions[$transition->Target]->ID;
            }
            $transition->write();
        }

        return $actions;
    }