original_string: public function onRelationManageCreate()
      {
          $this->forceManageMode = 'form';
          $this->beforeAjax();
          $saveData = $this->manageWidget->getSaveData();
          $sessionKey = $this->deferredBinding ? $this->relationGetSessionKey(true) : null;
  
          if ($this->viewMode == 'multi') {
              $newModel = $this->relationModel;
  
              /*
               * In special cases, has one/many will require a foreign key set
               * to pass any constraints imposed by the database. This emulates
               * the "create" method on the relation object.
               */
              if (in_array($this->relationType, ['hasOne', 'hasMany'])) {
                  $newModel->setAttribute(
                      $this->relationObject->getForeignKeyName(),
                      $this->relationObject->getParentKey()
                  );
              }
  
              $modelsToSave = $this->prepareModelsToSave($newModel, $saveData);
              foreach ($modelsToSave as $modelToSave) {
                  $modelToSave->save(null, $this->manageWidget->getSessionKey());
              }
  
              $this->relationObject->add($newModel, $sessionKey);
          }
          elseif ($this->viewMode == 'single') {
              $newModel = $this->viewModel;
              $this->viewWidget->setFormValues($saveData);
  
              /*
               * Has one relations will save as part of the add() call.
               */
              if ($this->deferredBinding || $this->relationType != 'hasOne') {
                  $newModel->save(null, $this->manageWidget->getSessionKey());
              }
  
              $this->relationObject->add($newModel, $sessionKey);
  
              /*
               * Belongs to relations won't save when using add() so
               * it should occur if the conditions are right.
               */
              if (!$this->deferredBinding && $this->relationType == 'belongsTo') {
                  $parentModel = $this->relationObject->getParent();
                  if ($parentModel->exists) {
                      $parentModel->save();
                  }
              }
          }
  
          return $this->relationRefresh();
      }
code: public function onRelationManageCreate()
      {
          $this->forceManageMode = 'form';
          $this->beforeAjax();
          $saveData = $this->manageWidget->getSaveData();
          $sessionKey = $this->deferredBinding ? $this->relationGetSessionKey(true) : null;
  
          if ($this->viewMode == 'multi') {
              $newModel = $this->relationModel;
  
              /*
               * In special cases, has one/many will require a foreign key set
               * to pass any constraints imposed by the database. This emulates
               * the "create" method on the relation object.
               */
              if (in_array($this->relationType, ['hasOne', 'hasMany'])) {
                  $newModel->setAttribute(
                      $this->relationObject->getForeignKeyName(),
                      $this->relationObject->getParentKey()
                  );
              }
  
              $modelsToSave = $this->prepareModelsToSave($newModel, $saveData);
              foreach ($modelsToSave as $modelToSave) {
                  $modelToSave->save(null, $this->manageWidget->getSessionKey());
              }
  
              $this->relationObject->add($newModel, $sessionKey);
          }
          elseif ($this->viewMode == 'single') {
              $newModel = $this->viewModel;
              $this->viewWidget->setFormValues($saveData);
  
              /*
               * Has one relations will save as part of the add() call.
               */
              if ($this->deferredBinding || $this->relationType != 'hasOne') {
                  $newModel->save(null, $this->manageWidget->getSessionKey());
              }
  
              $this->relationObject->add($newModel, $sessionKey);
  
              /*
               * Belongs to relations won't save when using add() so
               * it should occur if the conditions are right.
               */
              if (!$this->deferredBinding && $this->relationType == 'belongsTo') {
                  $parentModel = $this->relationObject->getParent();
                  if ($parentModel->exists) {
                      $parentModel->save();
                  }
              }
          }
  
          return $this->relationRefresh();
      }
code_tokens: public function onRelationManageCreate ( ) { $ this -> forceManageMode = 'form' ; $ this -> beforeAjax ( ) ; $ saveData = $ this -> manageWidget -> getSaveData ( ) ; $ sessionKey = $ this -> deferredBinding ? $ this -> relationGetSessionKey ( true ) : null ; if ( $ this -> viewMode == 'multi' ) { $ newModel = $ this -> relationModel ; /*
               * In special cases, has one/many will require a foreign key set
               * to pass any constraints imposed by the database. This emulates
               * the "create" method on the relation object.
               */ if ( in_array ( $ this -> relationType , [ 'hasOne' , 'hasMany' ] ) ) { $ newModel -> setAttribute ( $ this -> relationObject -> getForeignKeyName ( ) , $ this -> relationObject -> getParentKey ( ) ) ; } $ modelsToSave = $ this -> prepareModelsToSave ( $ newModel , $ saveData ) ; foreach ( $ modelsToSave as $ modelToSave ) { $ modelToSave -> save ( null , $ this -> manageWidget -> getSessionKey ( ) ) ; } $ this -> relationObject -> add ( $ newModel , $ sessionKey ) ; } elseif ( $ this -> viewMode == 'single' ) { $ newModel = $ this -> viewModel ; $ this -> viewWidget -> setFormValues ( $ saveData ) ; /*
               * Has one relations will save as part of the add() call.
               */ if ( $ this -> deferredBinding || $ this -> relationType != 'hasOne' ) { $ newModel -> save ( null , $ this -> manageWidget -> getSessionKey ( ) ) ; } $ this -> relationObject -> add ( $ newModel , $ sessionKey ) ; /*
               * Belongs to relations won't save when using add() so
               * it should occur if the conditions are right.
               */ if ( ! $ this -> deferredBinding && $ this -> relationType == 'belongsTo' ) { $ parentModel = $ this -> relationObject -> getParent ( ) ; if ( $ parentModel -> exists ) { $ parentModel -> save ( ) ; } } } return $ this -> relationRefresh ( ) ; }
docstring: Create a new related model
docstring_tokens: Create a new related model