/** * get or create an instance of Object * @param string|integer $pId * @param string|integer $pLocalObjectCollection not used but we need to have it to match with LocalModel * @param boolean $pIsloaded * @param boolean $pUpdateLoadStatus if true and object already exists update load status * @return array [Object,string] second element is the key in ObjectCollection where we can found Object returned */ protected function _getOrCreateObjectInstance($pId, $pLocalObjectCollection = null, $pIsloaded = true, $pUpdateLoadStatus = true) { if (!$this->hasIdProperty()) { $lMainObject = $this->getObjectInstance($pIsloaded); MainObjectCollection::getInstance()->addObject($lMainObject); //trigger_error("new main without id $pId, $this->mModelName"); } else { $lMainObject = MainObjectCollection::getInstance()->getObject($pId, $this->mModelName); if (is_null($lMainObject)) { $lMainObject = $this->_buildObjectFromId($pId, $pIsloaded); MainObjectCollection::getInstance()->addObject($lMainObject); //trigger_error("new main $pId, $this->mModelName"); } else { if ($pUpdateLoadStatus) { //trigger_error("main already added $pId, $this->mModelName"); //trigger_error("update main status ".var_export($lMainObject->isLoaded(), true)); $lMainObject->setLoadStatus(); } else { //trigger_error("main already added $pId, $this->mModelName doesn't update"); } } } return $lMainObject; }
if (count($lMainParentTestDb->getValue('childrenTestDb')->getValues()) != 6) { throw new Exception('bad children count'); } foreach ($lMainParentTestDb->getValue('childrenTestDb')->getValues() as $lValue) { if (array_key_exists($lValue->getId(), $lTestDbById)) { if ($lValue !== $lTestDbById[$lValue->getId()]) { throw new Exception('foreign value different than existing value'); } } else { if ($lValue->isLoaded()) { throw new Exception('foreign value must be unloaded'); } } } /** ****************************** test load ids composition value ****************************** **/ $lTestDbs = MainObjectCollection::getInstance()->getModelObjects('testDb'); $lTestDbById = []; foreach ($lTestDbs as $lTestDb) { $lTestDbById[$lTestDb->getId()] = $lTestDb; if ($lTestDb->isLoaded() && $lTestDb->getValue('mainParentTestDb') !== $lMainParentTestDb) { throw new Exception('foreign value different than existing value'); } } $lMainParentTestDb->deleteValue('childrenTestDb'); $lMainParentTestDb->setValue('childrenTestDb', $lMainParentTestDb->getModel()->getpropertyModel('childrenTestDb')->getObjectInstance(false)); if ($lMainParentTestDb->getValue('childrenTestDb')->isLoaded()) { throw new Exception('foreign value must be unloaded'); } $lMainParentTestDb->loadValue('childrenTestDb'); if (!$lMainParentTestDb->getValue('childrenTestDb')->isLoaded()) { throw new Exception('foreign value must be loaded');