/** * Called by $this->load() to populate data into $this->persistent->rec_data * * Subclasses may override this method to tune load() behavior, e.g. * to load data lazily by field name passed in $field_or_db_row. * Subclasses overriding this should also call parent::doLoad() since the base class * uses it to load data from $this->m model. * * @param array $field_or_db_row see $this->load() * @throws waException */ protected function doLoad($field_or_db_row = null) { // load from array? if (is_array($field_or_db_row)) { $fields = $this->m->getMetadata(); $nulls = array_fill_keys(array_keys($fields), null); $this->persistent->setAll(array_intersect_key($field_or_db_row, $fields) + $nulls); return; } // requested field already loaded? if ($field_or_db_row) { // check if can be loaded from $this->m model if (!array_key_exists($field_or_db_row, $this->m->getMetadata())) { return; } } else { $loaded = true; foreach ($this->m->getMetadata() as $f => $v) { if (!$this->persistent->keyExists($f)) { $loaded = false; break; } } if ($loaded) { return; } } // load from model $row = $this->m->getById($this->id); if (!$row) { throw new waException('No record found in ' . $this->m->getTableName() . ' for id=' . $this->id, 404); } $this->persistent->setAll($row); }