original_string: protected function _mergeAssociation($original, $assoc, $value, $options)
      {
          if (!$original) {
              return $this->_marshalAssociation($assoc, $value, $options);
          }
          if (!is_array($value)) {
              return null;
          }
  
          $targetTable = $assoc->getTarget();
          $marshaller = $targetTable->marshaller();
          $types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
          if (in_array($assoc->type(), $types)) {
              return $marshaller->merge($original, $value, (array)$options);
          }
          if ($assoc->type() === Association::MANY_TO_MANY) {
              return $marshaller->_mergeBelongsToMany($original, $assoc, $value, (array)$options);
          }
  
          if ($assoc->type() === Association::ONE_TO_MANY) {
              $hasIds = array_key_exists('_ids', $value);
              $onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
              if ($hasIds && is_array($value['_ids'])) {
                  return $this->_loadAssociatedByIds($assoc, $value['_ids']);
              }
              if ($hasIds || $onlyIds) {
                  return [];
              }
          }
  
          return $marshaller->mergeMany($original, $value, (array)$options);
      }
code: protected function _mergeAssociation($original, $assoc, $value, $options)
      {
          if (!$original) {
              return $this->_marshalAssociation($assoc, $value, $options);
          }
          if (!is_array($value)) {
              return null;
          }
  
          $targetTable = $assoc->getTarget();
          $marshaller = $targetTable->marshaller();
          $types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
          if (in_array($assoc->type(), $types)) {
              return $marshaller->merge($original, $value, (array)$options);
          }
          if ($assoc->type() === Association::MANY_TO_MANY) {
              return $marshaller->_mergeBelongsToMany($original, $assoc, $value, (array)$options);
          }
  
          if ($assoc->type() === Association::ONE_TO_MANY) {
              $hasIds = array_key_exists('_ids', $value);
              $onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
              if ($hasIds && is_array($value['_ids'])) {
                  return $this->_loadAssociatedByIds($assoc, $value['_ids']);
              }
              if ($hasIds || $onlyIds) {
                  return [];
              }
          }
  
          return $marshaller->mergeMany($original, $value, (array)$options);
      }
code_tokens: protected function _mergeAssociation ( $ original , $ assoc , $ value , $ options ) { if ( ! $ original ) { return $ this -> _marshalAssociation ( $ assoc , $ value , $ options ) ; } if ( ! is_array ( $ value ) ) { return null ; } $ targetTable = $ assoc -> getTarget ( ) ; $ marshaller = $ targetTable -> marshaller ( ) ; $ types = [ Association :: ONE_TO_ONE , Association :: MANY_TO_ONE ] ; if ( in_array ( $ assoc -> type ( ) , $ types ) ) { return $ marshaller -> merge ( $ original , $ value , ( array ) $ options ) ; } if ( $ assoc -> type ( ) === Association :: MANY_TO_MANY ) { return $ marshaller -> _mergeBelongsToMany ( $ original , $ assoc , $ value , ( array ) $ options ) ; } if ( $ assoc -> type ( ) === Association :: ONE_TO_MANY ) { $ hasIds = array_key_exists ( '_ids' , $ value ) ; $ onlyIds = array_key_exists ( 'onlyIds' , $ options ) && $ options [ 'onlyIds' ] ; if ( $ hasIds && is_array ( $ value [ '_ids' ] ) ) { return $ this -> _loadAssociatedByIds ( $ assoc , $ value [ '_ids' ] ) ; } if ( $ hasIds || $ onlyIds ) { return [ ] ; } } return $ marshaller -> mergeMany ( $ original , $ value , ( array ) $ options ) ; }
docstring: Creates a new sub-marshaller and merges the associated data.
  
  @param \Cake\Datasource\EntityInterface|\Cake\Datasource\EntityInterface[] $original The original entity
  @param \Cake\ORM\Association $assoc The association to merge
  @param array $value The data to hydrate
  @param array $options List of options.
  @return \Cake\Datasource\EntityInterface|\Cake\Datasource\EntityInterface[]|null
docstring_tokens: Creates a new sub - marshaller and merges the associated data .