/** * Creates a version of the current object and saves it. * * @param ConnectionInterface $con the connection to use * * @return ChildMenuVersion A version object */ public function addVersion($con = null) { $this->enforceVersion = false; $version = new ChildMenuVersion(); $version->setId($this->getId()); $version->setVisible($this->getVisible()); $version->setPosition($this->getPosition()); $version->setCreatedAt($this->getCreatedAt()); $version->setUpdatedAt($this->getUpdatedAt()); $version->setVersion($this->getVersion()); $version->setVersionCreatedAt($this->getVersionCreatedAt()); $version->setVersionCreatedBy($this->getVersionCreatedBy()); $version->setMenu($this); if ($relateds = $this->getMenuItems($con)->toKeyValue('Id', 'Version')) { $version->setMenuItemIds(array_keys($relateds)); $version->setMenuItemVersions(array_values($relateds)); } $version->save($con); return $version; }