Nextras\Orm\Entity\AbstractEntity::__clone PHP Method

__clone() public method

public __clone ( )
    public function __clone()
    {
        $id = $this->hasValue('id') ? $this->getValue('id') : null;
        $persistedId = $this->persistedId;
        foreach ($this->getMetadata()->getProperties() as $name => $metadataProperty) {
            if ($metadataProperty->isVirtual) {
                continue;
            }
            // getValue loads data & checks for not null values
            if ($this->hasValue($name) && is_object($this->data[$name])) {
                if ($this->data[$name] instanceof IRelationshipCollection) {
                    $data = iterator_to_array($this->data[$name]->get());
                    $this->data['id'] = null;
                    $this->persistedId = null;
                    $this->data[$name] = clone $this->data[$name];
                    $this->data[$name]->setParent($this);
                    $this->data[$name]->set($data);
                    $this->data['id'] = $id;
                    $this->persistedId = $persistedId;
                } elseif ($this->data[$name] instanceof IRelationshipContainer) {
                    $this->data[$name] = clone $this->data[$name];
                    $this->data[$name]->setParent($this);
                } else {
                    $this->data[$name] = clone $this->data[$name];
                }
            }
        }
        $this->data['id'] = null;
        $this->persistedId = null;
        $this->modified[null] = true;
        $this->preloadContainer = null;
        if ($repository = $this->repository) {
            $this->repository = null;
            $repository->attach($this);
        }
    }

Usage Example

 public function __clone()
 {
     parent::__clone();
     $this->preloadContainer = NULL;
 }