src/wcmf/application/controller/RESTController.php
public function createInRelation() {
    $this->requireTransaction();
    $request = $this->getRequest();

    // create new object
    $oidStr = null;
    $sourceOid = ObjectId::parse($request->getValue('sourceOid'));
    $relatedType = $this->getRelatedType($sourceOid, $request->getValue('relation'));
    $request->setValue('className', $relatedType);
    $subResponse = $this->executeSubAction('create');
    if (!$subResponse->hasErrors()) {
      $createStatus = $subResponse->getStatus();
      $targetOid = $subResponse->getValue('oid');
      $targetOidStr = $targetOid->__toString();

      // add new object to relation
      $request->setValue('targetOid', $targetOidStr);
      $request->setValue('role', $request->getValue('relation'));
      $subResponse = $this->executeSubAction('associate');
      if (!$subResponse->hasErrors()) {
        // add related object to subresponse similar to default update action
        $persistenceFacade = $this->getPersistenceFacade();
        $targetObj = $persistenceFacade->load($targetOid);
        $subResponse->setValue('oid', $targetOid);
        $subResponse->setValue($targetOidStr, $targetObj);
        $subResponse->setStatus($createStatus);

        // in case of success, return object only
        $oidStr = $subResponse->hasValue('oid') ? $subResponse->getValue('oid')->__toString() : '';
      }
    }

    // prevent commit
    if ($subResponse->hasErrors()) {
      $this->endTransaction(false);
    }
    $this->handleSubResponse($subResponse, $oidStr);
  }
public function createInRelation() {
    $this->requireTransaction();
    $request = $this->getRequest();

    // create new object
    $oidStr = null;
    $sourceOid = ObjectId::parse($request->getValue('sourceOid'));
    $relatedType = $this->getRelatedType($sourceOid, $request->getValue('relation'));
    $request->setValue('className', $relatedType);
    $subResponse = $this->executeSubAction('create');
    if (!$subResponse->hasErrors()) {
      $createStatus = $subResponse->getStatus();
      $targetOid = $subResponse->getValue('oid');
      $targetOidStr = $targetOid->__toString();

      // add new object to relation
      $request->setValue('targetOid', $targetOidStr);
      $request->setValue('role', $request->getValue('relation'));
      $subResponse = $this->executeSubAction('associate');
      if (!$subResponse->hasErrors()) {
        // add related object to subresponse similar to default update action
        $persistenceFacade = $this->getPersistenceFacade();
        $targetObj = $persistenceFacade->load($targetOid);
        $subResponse->setValue('oid', $targetOid);
        $subResponse->setValue($targetOidStr, $targetObj);
        $subResponse->setStatus($createStatus);

        // in case of success, return object only
        $oidStr = $subResponse->hasValue('oid') ? $subResponse->getValue('oid')->__toString() : '';
      }
    }

    // prevent commit
    if ($subResponse->hasErrors()) {
      $this->endTransaction(false);
    }
    $this->handleSubResponse($subResponse, $oidStr);
  }
public function createInRelation ( ) { $ this -> requireTransaction ( ) ; $ request = $ this -> getRequest ( ) ; // create new object $ oidStr = null ; $ sourceOid = ObjectId :: parse ( $ request -> getValue ( 'sourceOid' ) ) ; $ relatedType = $ this -> getRelatedType ( $ sourceOid , $ request -> getValue ( 'relation' ) ) ; $ request -> setValue ( 'className' , $ relatedType ) ; $ subResponse = $ this -> executeSubAction ( 'create' ) ; if ( ! $ subResponse -> hasErrors ( ) ) { $ createStatus = $ subResponse -> getStatus ( ) ; $ targetOid = $ subResponse -> getValue ( 'oid' ) ; $ targetOidStr = $ targetOid -> __toString ( ) ; // add new object to relation $ request -> setValue ( 'targetOid' , $ targetOidStr ) ; $ request -> setValue ( 'role' , $ request -> getValue ( 'relation' ) ) ; $ subResponse = $ this -> executeSubAction ( 'associate' ) ; if ( ! $ subResponse -> hasErrors ( ) ) { // add related object to subresponse similar to default update action $ persistenceFacade = $ this -> getPersistenceFacade ( ) ; $ targetObj = $ persistenceFacade -> load ( $ targetOid ) ; $ subResponse -> setValue ( 'oid' , $ targetOid ) ; $ subResponse -> setValue ( $ targetOidStr , $ targetObj ) ; $ subResponse -> setStatus ( $ createStatus ) ; // in case of success, return object only $ oidStr = $ subResponse -> hasValue ( 'oid' ) ? $ subResponse -> getValue ( 'oid' ) -> __toString ( ) : '' ; } } // prevent commit if ( $ subResponse -> hasErrors ( ) ) { $ this -> endTransaction ( false ) ; } $ this -> handleSubResponse ( $ subResponse , $ oidStr ) ; }
Create an object of a given type in the given relation

| Parameter        | Description
|------------------|-------------------------
| _in_ `language`  | The language of the object
| _in_ `className` | Type of object to create
| _in_ `sourceId`  | Id of the object to which the created objects are added (determines the object id together with _className_)
| _in_ `relation`  | Name of the relation to the object defined by _sourceId_ (determines the type of the created/added object)
| _out_            | Created object data

The object data is contained in POST content. If an existing object
should be added, an `oid` parameter in the object data is sufficient.
Create an object of a given type in the given relation