public function duplicateEntity($id)
    {
        $query = $this->_table;
        foreach ($this->_getFinder() as $finder) {
            $query = $query->find($finder);
        }

        $contain = $this->_getContain();

        if (!empty($contain)) {
            $query = $query->contain($contain);
        }

        $entity = $query->where([$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => $id])->firstOrFail();

        // process entity
        foreach ($this->getConfig('contain') as $contain) {
            $parts = explode('.', $contain);
            $this->_drillDownAssoc($entity, $this->_table, $parts);
        }

        $this->_modifyEntity($entity, $this->_table);

        foreach ($this->getConfig('remove') as $field) {
            $parts = explode('.', $field);
            $this->_drillDownEntity('remove', $entity, $parts);
        }

        foreach (['set', 'prepend', 'append'] as $action) {
            foreach ($this->getConfig($action) as $field => $value) {
                $parts = explode('.', $field);
                $this->_drillDownEntity($action, $entity, $parts, $value);
            }
        }

        return $entity;
    }
public function duplicateEntity($id)
    {
        $query = $this->_table;
        foreach ($this->_getFinder() as $finder) {
            $query = $query->find($finder);
        }

        $contain = $this->_getContain();

        if (!empty($contain)) {
            $query = $query->contain($contain);
        }

        $entity = $query->where([$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => $id])->firstOrFail();

        // process entity
        foreach ($this->getConfig('contain') as $contain) {
            $parts = explode('.', $contain);
            $this->_drillDownAssoc($entity, $this->_table, $parts);
        }

        $this->_modifyEntity($entity, $this->_table);

        foreach ($this->getConfig('remove') as $field) {
            $parts = explode('.', $field);
            $this->_drillDownEntity('remove', $entity, $parts);
        }

        foreach (['set', 'prepend', 'append'] as $action) {
            foreach ($this->getConfig($action) as $field => $value) {
                $parts = explode('.', $field);
                $this->_drillDownEntity($action, $entity, $parts, $value);
            }
        }

        return $entity;
    }
public function duplicateEntity ( $ id ) { $ query = $ this -> _table ; foreach ( $ this -> _getFinder ( ) as $ finder ) { $ query = $ query -> find ( $ finder ) ; } $ contain = $ this -> _getContain ( ) ; if ( ! empty ( $ contain ) ) { $ query = $ query -> contain ( $ contain ) ; } $ entity = $ query -> where ( [ $ this -> _table -> getAlias ( ) . '.' . $ this -> _table -> getPrimaryKey ( ) => $ id ] ) -> firstOrFail ( ) ; // process entity foreach ( $ this -> getConfig ( 'contain' ) as $ contain ) { $ parts = explode ( '.' , $ contain ) ; $ this -> _drillDownAssoc ( $ entity , $ this -> _table , $ parts ) ; } $ this -> _modifyEntity ( $ entity , $ this -> _table ) ; foreach ( $ this -> getConfig ( 'remove' ) as $ field ) { $ parts = explode ( '.' , $ field ) ; $ this -> _drillDownEntity ( 'remove' , $ entity , $ parts ) ; } foreach ( [ 'set' , 'prepend' , 'append' ] as $ action ) { foreach ( $ this -> getConfig ( $ action ) as $ field => $ value ) { $ parts = explode ( '.' , $ field ) ; $ this -> _drillDownEntity ( $ action , $ entity , $ parts , $ value ) ; } } return $ entity ; }
Creates duplicate Entity for given record id without saving it.

@param int|string $id Id of entity to duplicate.
@return \Cake\Datasource\EntityInterface
Creates duplicate Entity for given record id without saving it .