/** * Get a single instance of an entity by its database record id * * @param int $id The id of the entity * * @return BaseEntityAbstract */ public function findById($id) { $results = Dao::findById($this->_query->setSelectActiveOnly(false), $id); $this->resetQuery(); return $results; }
/** * Lazy load a many-to-one relationship * * @param string $property The property that we are trying to load * * @return BaseEntityAbstract */ protected function loadManyToOne($property) { $this->__loadDaoMap(); if (is_null($this->{$property})) { //if the proerty is allow to have null value, then let it be if (DaoMap::$map[strtolower(get_class($this))][$property]['nullable']) { $this->{$property} = null; return $this; } //if the property is one of these, as when we are trying to save them, we don't have the iniated value if (in_array($property, array('createdBy', 'updatedBy'))) { $this->{$property} = Core::getUser(); } else { throw new Exception('Property (' . get_class($this) . '::' . $property . ') must be initialised to integer or proxy prior to lazy loading.', 1); } } // Load the DAO map for this entity $cls = DaoMap::$map[strtolower(get_class($this))][$property]['class']; if (!$this->{$property} instanceof BaseEntityAbstract) { throw new DaoException('The property(' . $property . ') for "' . get_class($this) . '" is NOT a BaseEntity!'); } $qry = new DaoQuery($cls); $qry->setSelectActiveOnly(false); $this->{$property} = Dao::findById($qry, $this->{$property}->getId()); return $this; }