/** * @throws Gpf_Exception */ protected function doOneRowLoaded(Gpf_DbEngine_Row $row, $tempRow) { $primaryColumns = $row->getPrimaryColumns(); foreach ($primaryColumns as $column) { if ($tempRow->get($column->getName()) != $row->get($column->getName())) { $this->throwException(); } } }
public function __construct(array $columnMapping, Gpf_DbEngine_Row $parentRow, $mandatoryParent = true, $message = null) { foreach ($parentRow->getPrimaryColumns() as $column) { if (!in_array($column->getName(), $columnMapping)) { throw new Gpf_Exception("Column %s is not part of primary key", $column->getName()); } } $this->columnMapping = $columnMapping; $this->parentRow = $parentRow; $this->mandatoryParent = $mandatoryParent; if ($message != null) { $this->message = $message; } else { $this->message = $this->_("Relation constraint"); } }
/** * Validate Db_Row * * @param Gpf_DbEngine_Row $row * @throws Gpf_DbEngine_Row_ConstraintException */ public function validate(Gpf_DbEngine_Row $row) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->add('COUNT(*)', 'cnt'); $select->from->add($row->getTable()->name()); foreach ($row->getPrimaryColumns() as $primaryColumn) { $select->where->add($primaryColumn->getName(), '<>', $row->get($primaryColumn->getName())); } $conditionNotEqalColumns = new Gpf_SqlBuilder_CompoundWhereCondition(); foreach ($this->columnsNotEqualNames as $columnNotEqualName) { $conditionNotEqalColumns->add($columnNotEqualName, '=', $row->get($this->columnName), 'OR'); } $select->where->addCondition($conditionNotEqalColumns); $select->limit->set(0, 1); if ($select->getOneRow()->get('cnt') > 0) { $this->throwException(); } }