/** * Using the supplied source table row, retrieve the initial value for * this relationship. This is typically called by \Dewdrop\Db\Row when * get() is first called for this relationship. * * @param Row $row * @return array */ public function loadInitialValue(Row $row) { $value = $row->get($this->getSourceColumnName()); // If the anchor column has no value, we can assume this relationship has no value if (!$value) { return array(); } $db = $row->getTable()->getAdapter(); $stmt = $db->select(); $whereName = $db->quoteIdentifier("{$this->xrefTableName}.{$this->getXrefAnchorColumnName()}"); $stmt->from($this->xrefTableName, array($this->getXrefReferenceColumnName()))->where("{$whereName} = ?", $value); return $db->fetchCol($stmt); }
/** * Assign the provided row object to the named model. This will iterate * over all the fields and call setRow() on each one associated with * the named model so that their values can be set and retrieved for * editing. * * @throws \Dewdrop\Fields\Exception * @param string $modelName * @param Row $row * @return RowEditor */ public function setRow($modelName, Row $row) { $model = $this->getModel($modelName); if ($model !== $row->getTable()) { throw new Exception('The row should be from the same table instance.'); } foreach ($this->fields as $field) { if ($field instanceof DbField && $field->getTable() === $model) { $field->setRow($row); } } if ($this->deleteField) { $this->deleteField->setRow($row); } if (array_key_exists($modelName, $this->defaultsByModelName)) { $this->applyDefaultsToRow($row, $this->defaultsByModelName[$modelName]); } $this->rowsByName[$modelName] = $row; return $this; }